Datatable Adding Row
-
I'm returning a datatable from the DB, I need to add a row to that datatable for display only. That piece is working fine, the issue is I need that record to be the first record displayed in the cbo box. System.Data.DataRow dr = WorkTable.NewRow(); WorkTable.Rows.Add(new object[] {"ALL", "AL","","","","","","",-2,1,"UNKNOWN"}); cbo.DataSource = WorkTable; --I need to have the added line first in the combo box. Thanks
-
I'm returning a datatable from the DB, I need to add a row to that datatable for display only. That piece is working fine, the issue is I need that record to be the first record displayed in the cbo box. System.Data.DataRow dr = WorkTable.NewRow(); WorkTable.Rows.Add(new object[] {"ALL", "AL","","","","","","",-2,1,"UNKNOWN"}); cbo.DataSource = WorkTable; --I need to have the added line first in the combo box. Thanks
Instead of setting the data source of the combobox to the table, set it to a sorted view. Then all you need to do is make sure that the view is sorted so that your new row is first ... perhaps by adding a new column to the table that is null for everything other than your new row. I tried this quickly, and seems to work OK, but it looks like the sort put's null values ahead of non-nulls, so you'll need to do a descending sort. ----- In the land of the blind, the one eyed man is king.