Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am working on windows form app. i m displaying my data on grid view with two extra column name, checkbox and combobox column on each row. i want when i tick checkbox it must not let me choose any thing from combobox for only that particular Row. but for rest of the rows with unselected check box i must be able to select value from combobox.
Posted
Comments
Shanu2rick 26-Feb-13 4:39am    
is the data coming from database?
ByakuyaKuchiki 26-Feb-13 4:41am    
for combobox i have items inserted in form.
i just want to enable mean dont allow user to drop down combobox selected combobox.
and i am selecting it through ticking check box
Shanu2rick 26-Feb-13 4:46am    
you just want to enable and disable the combobox using that checkbox, right?
ByakuyaKuchiki 26-Feb-13 4:44am    
i have used this code. but it enable all the drop down even if i tick one check box

for (int i = 0; i <= GridView1.Rows.Count -1; i++)
{
object obj = GridView1.Rows[i].Cells[0];
if (((obj != null)))
{
DataGridViewCheckBoxCell checkBox1 = (DataGridViewCheckBoxCell)obj;
object objValue = checkBox1.Value;

if (objValue != null)
{
bool @checked = (bool)objValue;
if ((@checked))
{
//splitmethod is combobox
SplitMethod.ReadOnly = true;
}
else
{
SplitMethod.ReadOnly = false;
}

}
}
}
Shanu2rick 26-Feb-13 4:47am    
on which event are you performing this action?

1 solution

Make a little change in your code
C#
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

and in the GridView1_CellStateChanged event without directly applying this
C#
SplitMethod.ReadOnly = true;// it will always make the whole column readonly

try using this
C#
dataGridView1.CurrentRow.Cells[i].ReadOnly = true;//i is the column index of the combobox column

For further query feel free to ask.
 
Share this answer
 
v2
Comments
ByakuyaKuchiki 26-Feb-13 5:28am    
this what i did but its not working.
it is enabling all the combobox now.

private void GridView1_CellStateChanged(object sender, DataGridViewCellStateChangedEventArgs e)
{for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
object obj = GridView1.Rows[i].Cells[0];
if (((obj != null)))
{
DataGridViewCheckBoxCell checkBox1 = (DataGridViewCheckBoxCell)obj;
object objValue = checkBox1.Value;

GridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

if (objValue != null)
{
bool @checked = (bool)objValue;
if ((@checked))
{

GridView1.CurrentRow.Cells[i].ReadOnly = true;
// SplitMethod.ReadOnly = true;//splitmethod is name for combobox
}
else
{
GridView1.CurrentRow.Cells[i].ReadOnly = false;
//SplitMethod.ReadOnly = false;
}
}
}
}
}
Shanu2rick 26-Feb-13 5:30am    
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
this line should be written in the form load event, then try it again.
ByakuyaKuchiki 26-Feb-13 5:51am    
i can still select combobox.
remember it spouse to stop user to select any thing from combobox if check box is ticked.
each row has its own combo box and check box.
Shanu2rick 27-Feb-13 0:13am    
then remove the for loop and place your code in CurrentCellDirtyStateChanged Event which works only on the current cell of that specific checkbox.

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