I have one grid with some contents and one combobox, i want to change colur of cell based on the combox selected index change event.
Problem is I am not able to interate through grid row.
Could you please let tell me how to do that ?
Hi,
I didn't get your question clearly. Do you have a combo box in grid or out side the grid?
Combo box is not part of grid and I want to change colur of cell in one of the column of grid based on selection of contents in combo box
Normal 0 false false false MicrosoftInternetExplorer4
If you are not having any condition related to the grid, then you need not iterate through the gird. u can try the below code.
Grid.DisplayLayout.Bands[0].Columns[ColumnName].CellAppearance.BackColor = Color.Red;
In other way, if you have any conditon related to the grid. To iterate through the grid rows, try below code.
if(_comboBoxColors.SelectedIndex == (int) SelectedColor.Red)
{
for (int rowindex = 0; rowindex < _ugSteps.Rows.Count; rowindex ++) {
Here comes your condition....... then the below lines of code.... Grid.Rows[rowindex ].Cells[ColumnName].Appearance.BackColor = Color.Red
}
In my example, SelectedColor is a enumeration which contains all colors...
If u want to change the color of the cell, u can try
Grid.Rows[rowIndex].Cells[ColumnName].Appearance.BackColor = Color.Red
To change the text color of the cell,
Grid.Rows[rowIndex].Cells[ColumnName].Appearance.ForeColor= Color.Black
In the ComboBox "SelectedIndexChanged" event, u can add the code to change the cell color.