Same DataGrid Issue

  • Thread starter Arvind P Rangan
  • 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.
 
M

Martin Dechev

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
 
A

Arvind P Rangan

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top