Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I have many many rows added to a datagrid. there is a checkbox in the first column of each row. i need to be able to extract the data for each checked row, and also count all the checked rows. does anyone know how to do this. i added the check box in the column properties of the datagrid in the visual studio designer, in case that matters.
  • 1 month later...
Posted

Hi,

 

If your datagrid's datasource is an DataTable, you can use a DataView to filter rows and have the rows Count. Example:

DataView dv = new DataView((DataTable)yourDataGrid.DataSource,"CheckedColumnName = True        ", "CheckedColumnName",DataViewRowState.CurrentRows);

int checkedRowsCounter = dv.Count;
Console.WriteLine(string.Format("Checked Rows = {0}",checkedRowsCounter ));

 

OR

 

you can spend more time and code and write a FOR EACH statement instead like:

 

           int counter = 0;

           foreach(DataGridViewRow dr in myDataGridView.Rows)
           {
               if ((bool)dr.Cells["myCheckBoxColumnName"].Value == true)
               {
                   counter++;
               }
           }

           //output
           Console.WriteLine(counter.ToString());

 

i hope it helps,

 

Best Regards,

Tiago Teixeira

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...