Sorting a boolean column in datagridview +vb.net 2005 windows programming

Hi,
I am struggling on how to sort a boolean column in datagridview.
When grid is bound with datatable the column has no value in it.Now when I check the row the item value of the boolean column value  is true and when uncheck it the value gets false.
When the column is sorted it sorts by the false and blank value.This is a problem how do I make blank and false same when sorted.Any suggestions?
RIASAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
John (Yiannis) ToutountzoglouConnect With a Mentor Instructor Multiengine PilotCommented:
Other way is to sort in a default View before populate the datagridview...
Try the Function Below


ortDataTable(YourDataTable, B,"YourColumnName", True)
Private Function SortDataTable(ByVal dTable As DataTable, ByVal ColumnName As String, Optional ByVal OrderByAsc As Boolean = True) As DataView
Dim dView As New DataView(dTable)

If OrderByAsc Then
dView.Sort = ColumnName & " ASC"
Else
dView.Sort = ColumnName & " DESC"
End If

Return dView
End Function

Open in new window

0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
1.What do you mean with Blank Value
2.Set the ThreeState of datagridviewCheckBoxColumn to false
me.DatagridviewCheckBoxColumn.ThreeState=False
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Otehr Question ..Isn't the column contains CheckBoxes A DatagridView CheckBoxColumn?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
RIASAuthor Commented:
Hi,
No its a not a checkbox column it is a

dtTemp.Columns.Add("Selection", GetType(Object))
so it has a false or true value as I didnt want he checkboxes to appear in the column I created a column like the above.
 
0
 
RIASAuthor Commented:
Blank Value is dbnull value
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
I think that the column add method requires string,string
Me.datagriview1.Columns.Add("ColumnName" as string,HeaderText as string)
0
 
RIASAuthor Commented:
But how do you add a object column to datatable.Isn't this the way
dtTemp.Columns.Add("Selection", GetType(Object))  
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
a sory it is a datatable...
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
also try
Me.DataGridView1.Sort(Me.DataGridView1.Columns("SortCol"), System.ComponentModel.ListSortDirection.Ascending)
0
 
RIASAuthor Commented:
Cheers!!!
0
All Courses

From novice to tech pro — start learning today.