fguihen Posted March 30, 2007 Posted March 30, 2007 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. Quote
teixeira Posted May 16, 2007 Posted May 16, 2007 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.