I have a DataGridViewComboxColum named “cbxActionType” on my windows form application which have the following values in its item collection. • For Information • For Comment • For Review … etc. DataGridView1 has a column named “NDays” which stores numbers of days. How do I set the NDays column value to 0 (zero days) if the “cbxActionType” selected value is changed to “For Information”?
Asked
Active
Viewed 73 times
0
-
One possible way to do this is to wire-up the grids `CellValueChanged` event. In this event, check to see if the changed cell is in the “Action Type” column, If the changed value is in that column, then set the “Days” value accordingly on that row. – JohnG Feb 27 '19 at 02:34
-
Thank you @JohnG, I have the following code on CellValueChanged event to solve this issue but it doesn't go inside the if condition block. – Khalid Feb 28 '19 at 19:38
1 Answers
0
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.CurrentRow.Cells["cbxActionType"].Value == "For Information")
{
dataGridView1.CurrentRow.Cells["NDays"].Value = 0;
}
}
-
Add `ToString()` to the `Value` in the "if".... like.... `if (dataGridView1.CurrentRow.Cells["cbxActionType"].Value.ToString() == "For Information")` – JohnG Mar 01 '19 at 00:12
-
@JohnG thank you for pointing me to the right solution. appreciate for the efforts. – Khalid Mar 01 '19 at 07:53