GridView checkbox cell
-
Hi, I have a gridview where the first column is a checkbox. When I open the grid, the value of the first checkbox is always false, no matter how it is initialized. When I select another cell, the correct state appears. How could I have the correct value be shown?
-
Hi, I have a gridview where the first column is a checkbox. When I open the grid, the value of the first checkbox is always false, no matter how it is initialized. When I select another cell, the correct state appears. How could I have the correct value be shown?
-
Without seeing some of your code it is impossible to guess why this may be happening. How do you initialise the checkbox?
ok, here is my intitialization:
foreach (Linie lrow in ud.Linien) { LLinGrid.Rows.Add(); DataGridViewRow gr = LLinGrid.Rows\[LLinGrid.NewRowIndex - 1\]; gr.Cells\["global"\].Value = Convert.ToString(lrow.Global); gr.Cells\["ust"\].Value = Convert.ToString(lrow.Ust); gr.Cells\["kennung"\].Value = Convert.ToString(lrow.Kennung); if ((lrow.Kennung & 0x80) != 0) gr.Cells\["isuz"\].Value = true; // set and shown correctly ! if ((lrow.Kennung & 0x40) != 0) gr.Cells\["aktiv"\].Value = true; // set and shown correctly ! gr.Cells\["dir"\].Value = Convert.ToString(lrow.Dir); **gr.Cells\["xmit"\].Value = true; // Debugger says : true, but shown as unchecked** }
if I move the "xmit" column from position 1 to >2, it works. I tried:
LLinGrid.ClearSelection(); LLinGrid.Rows\[0\].Cells\[1\].Selected = true; // select next cell LLinGrid.Invalidate(); LLinGrid.InvalidateCell(LLinGrid.Rows\[0\].Cells\[0\]); LLinGrid.Show(); LLinGrid.UpdateCellValue(0, 0);
All of those didn't show the desired result. The value for the checkbox in the first column stays unchecked until I move to the next cell. this happens only in the first row; follwing rows are correct.
-
ok, here is my intitialization:
foreach (Linie lrow in ud.Linien) { LLinGrid.Rows.Add(); DataGridViewRow gr = LLinGrid.Rows\[LLinGrid.NewRowIndex - 1\]; gr.Cells\["global"\].Value = Convert.ToString(lrow.Global); gr.Cells\["ust"\].Value = Convert.ToString(lrow.Ust); gr.Cells\["kennung"\].Value = Convert.ToString(lrow.Kennung); if ((lrow.Kennung & 0x80) != 0) gr.Cells\["isuz"\].Value = true; // set and shown correctly ! if ((lrow.Kennung & 0x40) != 0) gr.Cells\["aktiv"\].Value = true; // set and shown correctly ! gr.Cells\["dir"\].Value = Convert.ToString(lrow.Dir); **gr.Cells\["xmit"\].Value = true; // Debugger says : true, but shown as unchecked** }
if I move the "xmit" column from position 1 to >2, it works. I tried:
LLinGrid.ClearSelection(); LLinGrid.Rows\[0\].Cells\[1\].Selected = true; // select next cell LLinGrid.Invalidate(); LLinGrid.InvalidateCell(LLinGrid.Rows\[0\].Cells\[0\]); LLinGrid.Show(); LLinGrid.UpdateCellValue(0, 0);
All of those didn't show the desired result. The value for the checkbox in the first column stays unchecked until I move to the next cell. this happens only in the first row; follwing rows are correct.
Got it. I had
this.Show();
positioned before the initialization block above. This raises the BeginEdit event for the first cell which seems to prevent the altering via program. There are 2 ways to solve this: move
this.Show();
or insert
LLinGrid.EndEdit();
behind initialization, Thanx for your interest.