Notifications
Clear all
[Closed] DataGridView change cell background color issue
Oct 23, 2017 1:30 am
Hi,
I am trying to change a cell background color in DataGridView with a button,but something wrong with these codes and can not work fine,I want to change a cell background color when press a button on same line,switch white to black,next time press button switch color back,how to fix it or any one has a better solution?
Fn change_color s e =
(
if e.ColumnIndex==1 then
(
if s.rows.item[e.RowIndex].cells.item[0].style.BackColor==(dotnetclass "system.drawing.color").fromARGB 255 255 255 then
(
s.rows.item[e.RowIndex].cells.item[0].style.BackColor=(dotnetclass "system.drawing.color").fromARGB 0 0 0
)
else
(
s.rows.item[e.RowIndex].cells.item[0].style.BackColor=(dotnetclass "system.drawing.color").fromARGB 255 255 255
)
)
)
form_test = dotnetobject "MaxCustomControls.Maxform"
form_test.Text = "Color test"
form_test.StartPosition = form_test.StartPosition.Manual
form_test.Location = dotnetobject "System.Drawing.Point" 400 350
form_test.Size = dotnetobject "System.Drawing.Size" 400 300
gv_color = dotnetobject "DataGridView"
gv_color.Dock = gv_color.Dock.Fill
gv_color.ColumnHeadersVisible = gv_color.ShowEditingIcon = gv_color.RowHeadersVisible = off
gv_color.AllowUserToaddRows = gv_color.AllowUserToDeleteRows = off
gv_color.ColumnCount = 2
r0 = dotnetobject "DataGridViewRow"
c0 = dotnetobject "DataGridViewTextBoxCell"
c0.value = "Text"
c1 = dotnetobject "DataGridViewButtonCell"
c1.value = "Switch color"
r0.cells.AddRange #(c0,c1)
r1 = dotnetobject "DataGridViewRow"
c0 = dotnetobject "DataGridViewTextBoxCell"
c0.value = "Text"
c1 = dotnetobject "DataGridViewButtonCell"
c1.value = "Switch color"
r1.cells.AddRange #(c0,c1)
r2 = dotnetobject "DataGridViewRow"
c0 = dotnetobject "DataGridViewTextBoxCell"
c0.value = "Text"
c1 = dotnetobject "DataGridViewButtonCell"
c1.value = "Switch color"
r2.cells.AddRange #(c0,c1)
dotnet.addEventHandler gv_color "CellContentClick" change_color
gv_color.rows.Clear()
gv_color.rows.AddRange #(r0,r1,r2)
form_test.controls.addrange #(gv_color)
form_test.showmodeless()