Hi I have a DataGridView in which there are multiple columns, There is a check box Column which is unbound column.
I am Setting this checkBox cell value from outside source.
now what i want, i want to sort the DataGridview on the basis of CheckBox Checked Values.
How can i do this...... |
| Progress2007 Tuesday, July 07, 2009 9:47 AM |
' my 3rd column was a checkboxcolumn, hence index 2 is used.
' change it accordingly
' Unchecked at Top
DataGridView1.Sort(DataGridView1.Columns(2), System.ComponentModel.ListSortDirection.Ascending)
' OR
' Checked at top
DataGridView1.Sort(DataGridView1.Columns(2), System.ComponentModel.ListSortDirection.Descending)
Thanks
- Omie
Someone makes my heart skip a clock cycle ! |
| Omie Tuesday, July 07, 2009 11:01 AM |
' my 3rd column was a checkboxcolumn, hence index 2 is used.
' change it accordingly
' Unchecked at Top
DataGridView1.Sort(DataGridView1.Columns(2), System.ComponentModel.ListSortDirection.Ascending)
' OR
' Checked at top
DataGridView1.Sort(DataGridView1.Columns(2), System.ComponentModel.ListSortDirection.Descending)
Thanks
- Omie Someone makes my heart skip a clock cycle !
I have used ur code but its not working .......... |
| Progress2007 Tuesday, July 07, 2009 11:08 AM |
umm ? not working as in ? you mean you put this code in button's click event and is not sorting even after clicking button ? any error ? MsgBox(DataGridView1.SortedColumn.Name.ToString) put that line after my code and see which column it shows in message box.
Thanks
- Omie
Someone makes my heart skip a clock cycle ! |
| Omie Tuesday, July 07, 2009 11:12 AM |
umm ? not working as in ? you mean you put this code in button's click event and is not sorting even after clicking button ? any error ?
MsgBox(DataGridView1.SortedColumn.Name.ToString)
put that line after my code and see which column it shows in message box.
Thanks
- Omie Someone makes my heart skip a clock cycle !
Actually i am getting a exception " Data-bound DataGridView control can only be sorted on data-bound columns. Parameter name: dataGridViewColumn" as my all the columns are data bound except That CheckBox Column |
| Progress2007 Tuesday, July 07, 2009 11:17 AM |
As far as I know sorting from unbound column in bounded DGV is not supported.
Thanks
- Omie
Someone makes my heart skip a clock cycle ! |
| Omie Tuesday, July 07, 2009 11:27 AM |
See virtual mode, its usually used for maintaining values of unbounded columns after sorting using bounded columns but I dont have any idea if it can be used for vice-versa. http://msdn.microsoft.com/en-us/library/2b177d6d.aspx Also, am not sure but you could probably use a DataTable to show data from DGV and sort it in anyway you want, update it if table data is modified.. really not sure about this..
Thanks
- Omie
Someone makes my heart skip a clock cycle ! |
| Omie Tuesday, July 07, 2009 11:32 AM |
hello Progress,
You need to implement your own logic forSorting of unbound column.
refer following similarlink,
http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/f7d221cd-cebc-4582-aa6f-383c5767b4f2 |
| NareshG Wednesday, July 08, 2009 5:43 AM |