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. C#
  4. How to get DataGridView Checkbox Checked or not ! [modified]

How to get DataGridView Checkbox Checked or not ! [modified]

Scheduled Pinned Locked Moved C#
csharptutorial
6 Posts 4 Posters 0 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.
  • S Offline
    S Offline
    Sr Frank
    wrote on last edited by
    #1

    I have CheckBox in my datagridview1 and I am trying to get CheckBox is check or not. for(int i; i< datagridview1.rows.count; i++) { bool IsChecked = ((CheckBox)datagridview1.rows[i].Cell["ID"].Value).Checked; } Above code is not working,please let me know where I am wrong. I am using C#, VisualStudio2008. Thanks

    modified on Tuesday, April 6, 2010 7:50 AM

    L C 2 Replies Last reply
    0
    • S Sr Frank

      I have CheckBox in my datagridview1 and I am trying to get CheckBox is check or not. for(int i; i< datagridview1.rows.count; i++) { bool IsChecked = ((CheckBox)datagridview1.rows[i].Cell["ID"].Value).Checked; } Above code is not working,please let me know where I am wrong. I am using C#, VisualStudio2008. Thanks

      modified on Tuesday, April 6, 2010 7:50 AM

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

      Hi, I'm using something like this;

      bool IsChecked = (bool)row.Cells[0].Value;

      I are Troll :suss:

      S 1 Reply Last reply
      0
      • L Lost User

        Hi, I'm using something like this;

        bool IsChecked = (bool)row.Cells[0].Value;

        I are Troll :suss:

        S Offline
        S Offline
        Sr Frank
        wrote on last edited by
        #3

        Not Working! Error: Object reference not set to an instance of an object.

        L 1 Reply Last reply
        0
        • S Sr Frank

          Not Working! Error: Object reference not set to an instance of an object.

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

          Sr...Frank wrote:

          Not Working! Error: Object reference not set to an instance of an object.

          I'm guessing that "row" is NULL. Try this;

          for(int i; i < datagridview1.rows.count; i++)
          {
          bool IsChecked = (bool)datagridview1.rows[i].Cells[0].Value;
          }

          You can try the code below to compare against, should display the basic idea;

          public partial class MainForm : Form
          {
          DataGridView grid = new DataGridView();
          Button testButton = new Button();

          public MainForm()
          {
          	InitializeComponent();
          	
          	testButton.Dock = DockStyle.Bottom;
          	testButton.Click += delegate 
          	{  
          		bool result = (bool)grid.Rows\[0\].Cells\[0\].Value;
          		MessageBox.Show("Checked: " + result);
          	};
          	
          	grid.Dock = DockStyle.Fill;
          	grid.Columns.Add(new DataGridViewCheckBoxColumn());
          	grid.Rows.Add(true);
          	grid.Rows.Add(false);
          	
          	Controls.Add(grid);
          	Controls.Add(testButton);			
          }
          

          }

          Enjoy :)

          I are Troll :suss:

          1 Reply Last reply
          0
          • S Sr Frank

            I have CheckBox in my datagridview1 and I am trying to get CheckBox is check or not. for(int i; i< datagridview1.rows.count; i++) { bool IsChecked = ((CheckBox)datagridview1.rows[i].Cell["ID"].Value).Checked; } Above code is not working,please let me know where I am wrong. I am using C#, VisualStudio2008. Thanks

            modified on Tuesday, April 6, 2010 7:50 AM

            C Offline
            C Offline
            carlecomm
            wrote on last edited by
            #5

            Please change "bool IsChecked = ((CheckBox)datagridview1.rows[i].Cell["ID"].Value).Checked;" to "bool IsChecked = ((CheckBox)datagridview1.rows[i].Cell["ID"].FindControl["CheckBox1"]).Checked;" and have another try.

            A 1 Reply Last reply
            0
            • C carlecomm

              Please change "bool IsChecked = ((CheckBox)datagridview1.rows[i].Cell["ID"].Value).Checked;" to "bool IsChecked = ((CheckBox)datagridview1.rows[i].Cell["ID"].FindControl["CheckBox1"]).Checked;" and have another try.

              A Offline
              A Offline
              Ashrafuddin
              wrote on last edited by
              #6

              Not Working: Error:Object reference not set to an instance of an object. I am not able to use FindControl[] in windows applications using c# .net. So please does any one will provide my the suitable code.

              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