Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. GridView checkbox cell

GridView checkbox cell

Scheduled Pinned Locked Moved Windows Forms
cssquestion
4 Posts 2 Posters 15 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wild Thing
    wrote on last edited by
    #1

    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?

    L 1 Reply Last reply
    0
    • W Wild Thing

      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?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Without seeing some of your code it is impossible to guess why this may be happening. How do you initialise the checkbox?

      W 1 Reply Last reply
      0
      • L Lost User

        Without seeing some of your code it is impossible to guess why this may be happening. How do you initialise the checkbox?

        W Offline
        W Offline
        Wild Thing
        wrote on last edited by
        #3

        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.

        W 1 Reply Last reply
        0
        • W Wild Thing

          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.

          W Offline
          W Offline
          Wild Thing
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups