6 Replies - 687 Views - Last Post: 28 April 2014 - 06:02 AM Rate Topic: -----

#1 higherprimate  Icon User is offline

  • D.I.C Head

Reputation: -8
  • View blog
  • Posts: 84
  • Joined: 14-December 13

DataGridView and checkboxes

Posted 27 April 2014 - 03:38 PM

I have a datagrid where 2 of the columns are decimal values which I would like to use for calculatiions. I would like to have checkboxes or maybe a drop down menu where depending on which column I select I can use that value for the calculations ( 2 checkboxes per row, one for each column; you cannot select both). Something like

2 questions here. First, how do I set it up so that there is a checkbox for each of the 2 columns, no matter how many rows are in the table (the table can have any number of rows)? Secondly, how do I tie the event of selecting the checkbox to the decimal value for each row while ensuring only one checkbox per row is selected. I am using a windows form in c# and sql server database

Is This A Good Question/Topic? 0
  • +

Replies To: DataGridView and checkboxes

#2 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3812
  • View blog
  • Posts: 13,522
  • Joined: 12-December 12

Re: DataGridView and checkboxes

Posted 27 April 2014 - 04:25 PM

To clarify, do you want columns of your DataGridView to contain the checkboxes? In which case the first step is to investigate

DataGridViewCheckBoxColumn :MSDN

specifically the example at the bottom.

Once you've got the checkbox-columns that you need, then you can explore calculations and events of the these columns (or the DGV) to prevent both boxes being checked, probably by toggling them.

JFYI There is a DataGrid in WPF so it is better to use the full expression DataGridView to avoid confusion.

This post has been edited by andrewsw: 27 April 2014 - 04:30 PM

Was This Post Helpful? 1
  • +
  • -

#3 higherprimate  Icon User is offline

  • D.I.C Head

Reputation: -8
  • View blog
  • Posts: 84
  • Joined: 14-December 13

Re: DataGridView and checkboxes

Posted 27 April 2014 - 06:07 PM

Is there a property in the DataGridView control class where we can add a checkbox to an existing column in DataGridView? Or visually if we seelct edit columns...
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,466
  • Joined: 05-May 12

Re: DataGridView and checkboxes

Posted 27 April 2014 - 07:15 PM

I'm assuming you are talking about WinForms.

To an existing column, no. As shown in the link above, you can add another column that contains a checkbox.

As for when editing a column, again, no. As for when editing a column of a specific row, yes, you can customize the DataGridView to use custom editors.
Was This Post Helpful? 1
  • +
  • -

#5 higherprimate  Icon User is offline

  • D.I.C Head

Reputation: -8
  • View blog
  • Posts: 84
  • Joined: 14-December 13

Re: DataGridView and checkboxes

Posted 27 April 2014 - 07:51 PM

Ok so while it is not possible to add a checkbox to an existing column, I noticed that we can add checkbox columns that are 'databound' columns or 'unbound' columns. What' does this refer to? What I need 2 additional checkbox columns where only 1 per row can be checked up to 6 rows. Something like this:

http://sportselect.w.../Game-Lists.htm
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,466
  • Joined: 05-May 12

Re: DataGridView and checkboxes

Posted 27 April 2014 - 08:31 PM

Unbound columns are columns which are not bound to data in the data source that you set on the data grid view's DataSource property. So if bind a data grid view to some data source, and then add a column afterwards, that column in considered unbound. Alternately, you can create a data grid view with various columns, but for columns where you don't specify the DataPropertyName or no matching property name is found, then those columns are also considered unbound.
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,466
  • Joined: 05-May 12

Re: DataGridView and checkboxes

Posted 28 April 2014 - 06:02 AM

If you took a step back and rewrote your program in WPF instead of WinForms, you would have a much easier time in controlling the UI to be what you want.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1