Same DataGrid Issue

  • Thread starter Thread starter Arvind P Rangan
  • Start date Start date
A

Arvind P Rangan

Hi all,
Case:
DataGrid is having alternative colors.
on Edit Item Select can i change the background color of the edit item
template to the same color it had during the alternative item?

If so just help me out.
Thanks
aRvind.
 
Hi, Arvind P Rangan,

Yes, you can change the background color - just test in the EditCommand
handler if the new EditItemIndex is odd or even. Then set the EditItemStyle
properties to the corresponding ones in the ItemStyle or to those in the
AlternatingItemStyle respectively, i.e.:

[C#]
void MyDataGrid_Edit(Object sender, DataGridCommandEventArgs e)
{
MyDataGrid.EditItemStyle.BackColor =
(((e.Item.ItemIndex % 2) == 0) ?
MyDataGrid.ItemStyle.BackColor :
MyDataGrid.AlternatingItemStyle.BackColor)
//....
}

[VB.NET]
Sub MyDataGrid_Edit(s As Object, e As DataGridCommandEventArgs)
MyDataGrid.EditItemStyle.BackColor = IIf( _
(e.Item.ItemIndex Mod 2) = 0, _
MyDataGrid.ItemStyle.BackColor, _
MyDataGrid.AlternatingItemStyle.BackColor)
'....
End Sub

Hope this helps
Martin
 
Thanks MArtin,
Actually DAtaGrid handles those things by itself it will take the back color
of the respective item type.
Arvind
Martin Dechev said:
Hi, Arvind P Rangan,

Yes, you can change the background color - just test in the EditCommand
handler if the new EditItemIndex is odd or even. Then set the EditItemStyle
properties to the corresponding ones in the ItemStyle or to those in the
AlternatingItemStyle respectively, i.e.:

[C#]
void MyDataGrid_Edit(Object sender, DataGridCommandEventArgs e)
{
MyDataGrid.EditItemStyle.BackColor =
(((e.Item.ItemIndex % 2) == 0) ?
MyDataGrid.ItemStyle.BackColor :
MyDataGrid.AlternatingItemStyle.BackColor)
//....
}

[VB.NET]
Sub MyDataGrid_Edit(s As Object, e As DataGridCommandEventArgs)
MyDataGrid.EditItemStyle.BackColor = IIf( _
(e.Item.ItemIndex Mod 2) = 0, _
MyDataGrid.ItemStyle.BackColor, _
MyDataGrid.AlternatingItemStyle.BackColor)
'....
End Sub

Hope this helps
Martin
Arvind P Rangan said:
Hi all,
Case:
DataGrid is having alternative colors.
on Edit Item Select can i change the background color of the edit item
template to the same color it had during the alternative item?

If so just help me out.
Thanks
aRvind.
 
Back
Top