-
Mar 26th, 2014, 08:51 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Problem sorting a combo
Using vb 2012 I bind the combo to a datatable (TABLE). I also add a new row <None>.
Code:
Dim row As DataRow
row = TABLE.NewRow()
row("EmployeeID") = 0
row("EmployeeName") = "<None>"
TABLE.Rows.Add(row)
cboBuildingManager.DataSource = TABLE
cboBuildingManager.DisplayMember = "EmployeeName"
cboBuildingManager.ValueMember = "EmployeeID"
This works perfectly. However, I would like <None> to appear at the top of the list (hence the spelling), but when I sort the combo all the values get mixed up. The selected value is for the item below the one chosen and then it wraps around to the top on the bottom choice. So I suspect I have to sort the datatable before binding it. Sorting the names when loading the table is simple with sql .. but how do I sort after adding <None>? Or perhaps there is a better way to add <None> to the combo list. If I have to leave it on the bottom of the combo list I suppose I can but I would prefer it to be at the top.
TIA
Ken
-
Mar 26th, 2014, 09:01 AM
#2
Addicted Member
Re: Problem sorting a combo
after you add your <None> row, dim a dataview, add your table to it, sort the view, and use that as your datasource
Here's a link for reference
_____________
Tim
If anyone's answer has helped you, please show your appreciation by rating that answer.
When you get a solution to your issue remember to mark the thread Resolved.
reference links
-
Mar 26th, 2014, 09:02 AM
#3
Addicted Member
Re: Problem sorting a combo
Did you set the Sorted property of the combo box to true?
_____________
Tim
If anyone's answer has helped you, please show your appreciation by rating that answer.
When you get a solution to your issue remember to mark the thread Resolved.
reference links
-
Mar 26th, 2014, 09:52 AM
#4
Thread Starter
Addicted Member
Re: Problem sorting a combo
Thank you for the quick reply. Setting the sorted property of the combo resulted in scrambled results. However, using a dataview and sorting that did the trick. I've never used a dataview so I never thought of it. Thank you! For anyone else reading this I changed the code to:
Code:
Dim row As DataRow
row = TABLE.NewRow()
row("EmployeeName") = "<None>"
row("EmployeeID") = 0
TABLE.Rows.Add(row)
Dim dv As New DataView(TABLE)
dv.Sort = "EmployeeName ASC"
cboBuildingManager.DataSource = dv
cboBuildingManager.DisplayMember = "EmployeeName"
cboBuildingManager.ValueMember = "EmployeeID"
Thanks again!!
Ken
-
Mar 26th, 2014, 10:57 AM
#5
Addicted Member
Re: [RESOLVED] Problem sorting a combo
The sorted property is sorting on the value, EmployeeID, column is probably why. Missed that sorry. Glad you got it working.
_____________
Tim
If anyone's answer has helped you, please show your appreciation by rating that answer.
When you get a solution to your issue remember to mark the thread Resolved.
reference links
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|