In my datagridview, I have got some columns are read only
, so i have given in some color.
When I load the the DGV in advance view with all columns including read only.
When the user cliks on Normal View I want to just display the normal eitable cols and hide the read only columns and the color.
I'm on telerik and using radgrid.
I tried the below approach but it's not working. Is there any better way of doing this?? Thank you.
private void normalToolStripMenuItem_Click(object sender, EventArgs e)//Normal View
{
DTURradGridView.Columns[2].IsVisible = false;
DTURradGridView.Columns[3].IsVisible = false;
DTURradGridView.Columns[4].IsVisible = false;
DTURradGridView.Columns[5].IsVisible = false;
DTURradGridView.Columns[7].IsVisible = false;
DTURradGridView.Columns[11].IsVisible = false;
DTURradGridView.Columns[2].ReadOnly = false;
DTURradGridView.Columns[3].ReadOnly = false;
DTURradGridView.Columns[4].ReadOnly = false;
DTURradGridView.Columns[5].ReadOnly = false;
DTURradGridView.Columns[7].ReadOnly = false;
DTURradGridView.Columns[11].ReadOnly = false;
DTURradGridView.CellFormatting -= DTURradGridView_CellFormatting;
}
private void advancedToolStripMenuItem_Click(object sender, EventArgs e) //Advanced View
{
DTURradGridView.Columns[2].IsVisible = true;
DTURradGridView.Columns[3].IsVisible = true;
DTURradGridView.Columns[4].IsVisible = true;
DTURradGridView.Columns[5].IsVisible = true;
DTURradGridView.Columns[7].IsVisible = true;
DTURradGridView.Columns[11].IsVisible = true;
DTURradGridView.Columns[2].ReadOnly = true;
DTURradGridView.Columns[3].ReadOnly = true;
DTURradGridView.Columns[4].ReadOnly = true;
DTURradGridView.Columns[5].ReadOnly = true;
DTURradGridView.Columns[7].ReadOnly = true;
DTURradGridView.Columns[11].ReadOnly = true;
DTURradGridView.CellFormatting += DTURradGridView_CellFormatting;
}
private void DTURradGridView_CellFormatting(object sender, CellFormattingEventArgs e)
{
if (e.CellElement.ColumnIndex != 2 && e.CellElement.ColumnIndex != 3 && e.CellElement.ColumnIndex != 4
&& e.CellElement.ColumnIndex != 5 && e.CellElement.ColumnIndex != 7 && e.CellElement.ColumnIndex != 11) return;
e.CellElement.DrawFill = true;
e.CellElement.NumberOfColors = 1;
e.CellElement.BackColor = Color.LightSlateGray;
e.CellElement.GradientStyle = GradientStyles.Linear;
}
When I click on the normal view, I see the colors of the col index 2,3,4,5. So the -= is not working.