Click here to Skip to main content
14,970,700 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

On form1 I have datagridview, in code i add column type DataGridComboboxColumn and next 3 columns with normal text.

Combobox i fill like this:

foreach (DataRow row in ds.Tables["tbluslugi"].Rows)
        {
            nazwa.Items.Add(row["Nazwa"].ToString());
        }


I use event dataGridView1_CurrentCellDirtyStateChanged, after when i choose in combobox some value this event is Launch. But when i want get back value what was chosen, value = false. Value = chosen value when i go to next row and i this case i have to use event CellEndEdit but it`s look bad, when i choose somthing from combobox and nothing happend.

What i want? I want when i choose valuse form combobox (don`t wait to go next row) it`s looking in database this value, get back data and put it in empty cells in this row.



I have another quastion, how to make default item in datagridcombobox ?
Posted
Updated 26-May-11 14:16pm
v4

1 solution

I think I understand that you want the values in the text cells to change after a selection is made in the combo box.

If this is the case, use the EditingControlShowing event to setup the combo boxes change event.

Like this

private void dataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
    if(dataGridView.CurrentCell.ColumnIndex == 1)
    {
        ComboBox cmb = (ComboBox)e.Control;
        cmb.SelectedValueChanged += new EventHandler(cmb_SelectedValueChanged);
    }
}

void cmb_SelectedValueChanged(object sender, EventArgs e)
{
    //Update your 3 text fields here
}


Hope this helps
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900