Click here to Skip to main content
15,743,429 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have a datagridview with three columns : the first column is an editText box , the second and the third column are a comboboxcolumn of enum.

when i run the code, by default the first row is displayed with all fields are empty.
but the problem come when i click to the first cell (TextBox), the two other combobox cell take automatically their default values. but i don't want them to take any value unless i select it by myself.

is there any way to do it ?

for info the datasource of the datagridview is linked to a list.


What I have tried:

private void dgv_TableTarification_CellClick(object sender, DataGridViewCellEventArgs e)
     if (e.RowIndex < 0) //le click sur la cellule else le header n'entraine pas une exception
     if (e.ColumnIndex < 0)
     //if (e.ColumnIndex != 1)
     //  return;
     if (this.dgv_TableTarification.CurrentCell.ColumnIndex == 0)
       this.dgv_TableTarification.Rows[e.ColumnIndex].Cells["C_Tarif"].Selected = false;
       this.dgv_TableTarification.Rows[e.ColumnIndex].Cells["C_RELAIS"].Selected = false;

private void dgv_TableTarification_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
     e.Row.Cells["C_Tarif"].Value = string.Empty;
     e.Row.Cells["C_RELAIS"].Value = string.Empty;
Updated 7-Feb-19 5:58am

1 solution

Every Enum should have an explicit default (E.g. Unknown = 0) that would help in your situation.

"Lists" typically use the "SelectedIndex" to reflect "not selected" as -1.

"Selected" in your context means nothing. (And how does the compiler know you are referring to a combo box with your "generic" code?)
Share this answer
Member 13927859 8-Feb-19 4:39am    
yeah , every enum have a default value , but I don't want it show the default value unless I click on it , how does your example can help me , I didn't understand
Member 13927859 8-Feb-19 4:41am    
here is my enum : public enum Tarif
T1 = 0,
T2 = 1,
T3 = 2,
T4 = 3,
T5 = 4,
T6 = 5,
the combobow of this enum display a default value T1 which equal to 0 .

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