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. DataGridView problem

DataGridView problem

Scheduled Pinned Locked Moved C#
help
4 Posts 3 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.
  • T Offline
    T Offline
    t4ure4n
    wrote on last edited by
    #1

    Hello every body I am developing an application where i am using DataGridview it has following data Table : Roles --_--------------------------- | Role | Primary | Secondary | ------------------------------ Role is string type column Primary and Secondary are Boolean type columns (So they appear with a check box)

    i want to record the change of value of "Primary" and "Secondary" columns.

    That is I want to know if user checked or unchecked the value in any row in the last two columns

    o O º(`'·.,(`'·., ☆,.·''),.·'')º O o° »·'"`»* *☆ t4ure4n ☆* *«·'"`« °o O º(,.·''(,.·'' ☆`'·.,)`'·.,)º O o°

    H J 2 Replies Last reply
    0
    • T t4ure4n

      Hello every body I am developing an application where i am using DataGridview it has following data Table : Roles --_--------------------------- | Role | Primary | Secondary | ------------------------------ Role is string type column Primary and Secondary are Boolean type columns (So they appear with a check box)

      i want to record the change of value of "Primary" and "Secondary" columns.

      That is I want to know if user checked or unchecked the value in any row in the last two columns

      o O º(`'·.,(`'·., ☆,.·''),.·'')º O o° »·'"`»* *☆ t4ure4n ☆* *«·'"`« °o O º(,.·''(,.·'' ☆`'·.,)`'·.,)º O o°

      H Offline
      H Offline
      Hayder Marzouk
      wrote on last edited by
      #2

      hi, Don't think datagrid, think datasource. So ure solution is in the the datatable. use the ColumnChanged or ColumnChanging event of ure datatabl. Here an example : mydataTable.ColumnChanged += new DataColumnChangeEventHandler(mydataTable_ColumnChanged); void mydataTable_ColumnChanged(object sender, DataColumnChangeEventArgs e) { if (e.Column.ColumnName == "Primary" ||e.Column.ColumnName == "Secondary") { if (e.PropsedValue == true ) { //............. do something } } } HTH. Hayder Marzouk

      J 1 Reply Last reply
      0
      • T t4ure4n

        Hello every body I am developing an application where i am using DataGridview it has following data Table : Roles --_--------------------------- | Role | Primary | Secondary | ------------------------------ Role is string type column Primary and Secondary are Boolean type columns (So they appear with a check box)

        i want to record the change of value of "Primary" and "Secondary" columns.

        That is I want to know if user checked or unchecked the value in any row in the last two columns

        o O º(`'·.,(`'·., ☆,.·''),.·'')º O o° »·'"`»* *☆ t4ure4n ☆* *«·'"`« °o O º(,.·''(,.·'' ☆`'·.,)`'·.,)º O o°

        J Offline
        J Offline
        joon vh
        wrote on last edited by
        #3

        Are you just trying to retrieve the data from the datagridview columns? or are you trying to capture them into events. if it's the former, then you can simply do this:

                    dataGridView1.Columns.Add("foo", "foo");
                    DataGridViewCheckBoxColumn cbc = new DataGridViewCheckBoxColumn();
                    cbc.Name = "bar";
                    dataGridView1.Columns.Add(cbc);
                    dataGridView1.Rows.Add("xyzzy", true);
                    dataGridView1.Rows.Add("yzzyx", false);
        
                    Console.WriteLine((bool)((dataGridView1.Rows[0].Cells[1]).Value));
                    Console.WriteLine((bool)((dataGridView1.Rows[1].Cells[1]).Value));
        

        Cast the value of the cell you need into a bool, and you have the Checked value. ps: please don't randomly place layout tags over text in your post, makes it hard to read.


        Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

        1 Reply Last reply
        0
        • H Hayder Marzouk

          hi, Don't think datagrid, think datasource. So ure solution is in the the datatable. use the ColumnChanged or ColumnChanging event of ure datatabl. Here an example : mydataTable.ColumnChanged += new DataColumnChangeEventHandler(mydataTable_ColumnChanged); void mydataTable_ColumnChanged(object sender, DataColumnChangeEventArgs e) { if (e.Column.ColumnName == "Primary" ||e.Column.ColumnName == "Secondary") { if (e.PropsedValue == true ) { //............. do something } } } HTH. Hayder Marzouk

          J Offline
          J Offline
          joon vh
          wrote on last edited by
          #4

          That would only work if the datagridview was databound I think. If there is no underlying datasource/table you have to access the DGV directly. You can also use the datagridview.Click event to capture whether a checkbox was clicked, and get it's new value in the way I described below.


          Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

          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