Hi all,
I am using a DataGridView to handle my project’s data,I got stuck with changing cell’s background color,my goal is change color like these steps:
1.Press button “btn_change_color_01”,change color from cell 1 to 3
2.Press button “btn_change_color_02”,change color from cell 3 to 5
3.Press button “btn_change_color_03”,change color from cell 5 to 8
But when I clear the color and set color to new cells,the result was weird like below,does anyone knows how to fix it?
The codes:
(
global DataGridViewTest
try (destroydialog DataGridViewTest) catch()
change_color=(dotnetclass "system.drawing.color").fromARGB 12 128 232
rollout DataGridViewTest "DataGridView"
(
dotnetcontrol dgv "DataGridView" width:295 height:300 pos:[0,0] align:#center
button btn_change_color_01 "Change Color 01" pos:[105,325] width:110 height:25
button btn_change_color_02 "Change Color 02" pos:[105,365] width:110 height:25
button btn_change_color_03 "Change Color 03" pos:[105,405] width:110 height:25
on DataGridViewTest open do
(
dgv.Dock=dgv.Dock.Fill
dgv.RowHeadersVisible=false
dgv.columns.add (dotnetobject "DataGridViewCheckBoxColumn")
dgv.columns.add (dotnetobject "DataGridViewTextBoxColumn")
for i=0 to dgv.Columns.count-1 do dgv.Columns.Item[i].width=145
numCells=dgv.Columns.count-1
oddColor=(dotnetclass "system.drawing.color").fromARGB 243 243 243
evenColor= (dotnetclass "system.drawing.color").fromARGB 255 255 255
dgv.defaultCellStyle.backColor=evenColor
dgv.AlternatingRowsDefaultCellStyle.backColor=oddColor
dgv.SelectionMode=(dotNetClass "System.Windows.Forms.DataGridViewSelectionMode").FullRowSelect
for i=1 to 10 do
(
row=dgv.rows.item[dgv.rows.add()]
rowCells=row.cells
)
dgv.ClearSelection()
)
Fn Clear_color=
(
for j=0 to 1 do
(
for i=0 to (dgv.rows.count-1) do
(
dgv.rows.item[i].cells.item[j].Style.BackColor=undefined
)
)
)
on btn_change_color_01 pressed do
(
Clear_color()
for j=0 to 1 do
(
for i=1 to 3 do
(
dgv.rows.item[i].cells.item[j].Style.BackColor=change_color
)
)
)
on btn_change_color_02 pressed do
(
Clear_color()
for j=0 to 1 do
(
for i=3 to 5 do
(
dgv.rows.item[i].cells.item[j].Style.BackColor=change_color
)
)
)
on btn_change_color_03 pressed do
(
Clear_color()
for j=0 to 1 do
(
for i=5 to 8 do
(
dgv.rows.item[i].cells.item[j].Style.BackColor=change_color
)
)
)
)
createdialog DataGridViewTest 300 450
)




