Click here to Skip to main content
15,890,282 members
Home / Discussions / C#
   

C#

 
AnswerRe: Control forms of an app Pin
Nitheesh George24-Mar-11 20:30
Nitheesh George24-Mar-11 20:30 
GeneralRe: Control forms of an app Pin
dj_jeff24-Mar-11 21:28
dj_jeff24-Mar-11 21:28 
GeneralRe: Control forms of an app Pin
Nitheesh George24-Mar-11 22:45
Nitheesh George24-Mar-11 22:45 
GeneralRe: Control forms of an app Pin
dj_jeff25-Mar-11 0:11
dj_jeff25-Mar-11 0:11 
QuestionDatagridviewcomboboxcolumn SelectedIndexChanged not work properly Pin
Davey_guan24-Mar-11 3:34
Davey_guan24-Mar-11 3:34 
AnswerRe: Datagridviewcomboboxcolumn SelectedIndexChanged not work properly Pin
Henry Minute24-Mar-11 17:12
Henry Minute24-Mar-11 17:12 
GeneralRe: Datagridviewcomboboxcolumn SelectedIndexChanged not work properly Pin
Davey_guan25-Mar-11 19:48
Davey_guan25-Mar-11 19:48 
GeneralRe: Datagridviewcomboboxcolumn SelectedIndexChanged not work properly Pin
Henry Minute26-Mar-11 5:03
Henry Minute26-Mar-11 5:03 
OK.

Simply test for a valid dr before trying to do anything with it.
C#
private void dgcboDocNo_SelectedIndexChanged(object sender, EventArgs e)
{
    System.Diagnostics.Debug.WriteLine(dataGridView1.CurrentCell.ColumnIndex + "SelectedIndexChanged");

    string docno = ((DataGridViewComboBoxEditingControl)sender).Text.ToString();
    DataRow[] dr = myDs.Tables["DetailDocRegister"].Select("DocNo = '" + docno + "'");
    if (dr.Length > 0)  // <======================= TEST HERE ======================================================
    {
        int y = dataGridView1.CurrentCellAddress.Y;
        dataGridView1.Rows[y].Cells[1].Value = dr[0]["DocTitle"];
    }
}

Note that I have also changed your reference to string docno = ((ComboBox)sender).Text.ToString(); this is because the DataGridViewComboBoxEditingControl has properties and methods that a plain old ComboBox doesn't. One day you might need to use them so it's a good idea to get into the habit of using the proper control now. You should also do this in your EditingControlShowing handler:
C#
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
    DataGridViewComboBoxEditingControl combo = e.Control as DataGridViewComboBoxEditingControl;  // <=============== HERE ================
    System.Diagnostics.Debug.WriteLine(dataGridView1.CurrentCell.ColumnIndex + "EditControlShowing");
    if (combo != null)
    {
        combo.SelectedIndexChanged -= new EventHandler(dgcboDocNo_SelectedIndexChanged);
        combo.SelectedIndexChanged += new EventHandler(dgcboDocNo_SelectedIndexChanged);
    }
}


Hope this helps.
Henry Minute

Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.

GeneralRe: Datagridviewcomboboxcolumn SelectedIndexChanged not work properly Pin
Davey_guan26-Mar-11 20:01
Davey_guan26-Mar-11 20:01 
GeneralRe: Datagridviewcomboboxcolumn SelectedIndexChanged not work properly Pin
Henry Minute26-Mar-11 5:40
Henry Minute26-Mar-11 5:40 
Questionneed help in c# coding Pin
ULKA RAMAKRISHNAN24-Mar-11 2:16
ULKA RAMAKRISHNAN24-Mar-11 2:16 
AnswerRe: need help in c# coding Pin
Ravi Bhavnani24-Mar-11 2:19
professionalRavi Bhavnani24-Mar-11 2:19 
AnswerRe: need help in c# coding Pin
RobCroll24-Mar-11 2:26
RobCroll24-Mar-11 2:26 
Question.resources Edit Pin
obi.bin24-Mar-11 1:00
obi.bin24-Mar-11 1:00 
QuestionNew Version Update Pin
sachees12323-Mar-11 23:00
sachees12323-Mar-11 23:00 
AnswerRe: New Version Update Pin
RobCroll23-Mar-11 23:54
RobCroll23-Mar-11 23:54 
AnswerRe: New Version Update Pin
PIEBALDconsult26-Mar-11 5:47
mvePIEBALDconsult26-Mar-11 5:47 
QuestionHow do I defined property in C#? Pin
baisak23-Mar-11 19:03
baisak23-Mar-11 19:03 
AnswerRe: How do I defined property in C#? Pin
JF201523-Mar-11 19:05
JF201523-Mar-11 19:05 
AnswerRe: How do I defined property in C#? Pin
Pravin Patil, Mumbai23-Mar-11 22:18
Pravin Patil, Mumbai23-Mar-11 22:18 
AnswerRe: How do I defined property in C#? Pin
Nitheesh George24-Mar-11 2:50
Nitheesh George24-Mar-11 2:50 
AnswerRe: How do I defined property in C#? Pin
fjdiewornncalwe24-Mar-11 4:29
professionalfjdiewornncalwe24-Mar-11 4:29 
QuestionMiniHttpServer Pin
Pascal Ganaye23-Mar-11 16:02
Pascal Ganaye23-Mar-11 16:02 
AnswerRe: MiniHttpServer Pin
PIEBALDconsult23-Mar-11 16:06
mvePIEBALDconsult23-Mar-11 16:06 
AnswerRe: MiniHttpServer [modified] Pin
Dave Kreskowiak23-Mar-11 17:58
mveDave Kreskowiak23-Mar-11 17:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.