Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort a combobox

Status
Not open for further replies.

mrdance

Programmer
Apr 17, 2001
308
SE
I have a combobox with a datatable connected to it. How can I sort one column DESC? Here is my code:


DataTable dt = new DataTable("cboMC");
//DataView dv = new DataView(dt);
DataColumn dc1 = new DataColumn("SUBJECT");
dc1.DataType = typeof(string);
dt.Columns.Add(dc1);

DataColumn dc2 = new DataColumn("UNID");
dc2.DataType = typeof(int);
dt.Columns.Add(dc2);

DataColumn dc3 = new DataColumn("DATETIME");
dc3.DataType = typeof(DateTime);
dt.Columns.Add(dc3);

cboTest2.DataSource = dt;
cboTest2.DisplayMember = "SUBJECT";
cboTest2.ValueMember = "UNID";
//cboTest2.

DataRow drow = dt.NewRow();
drow["SUBJECT"] = "hej";
drow["UNID"] = 1;
drow["DATETIME"] = DateTime.Now;
dt.Rows.Add(drow);

DataRow drow2 = dt.NewRow();
drow2["SUBJECT"] = "hej2";
drow2["UNID"] = 2;
drow2["DATETIME"] = DateTime.Now;
dt.Rows.Add(drow2);


--- neteject.com - Internet Solutions ---
 
The data is received from a socket in no special order. Also, it's changed during runtime. I am not sure exactly what you mean, can I write SQL:s on this table at runtime to change the order? Please give me an example of how, I can from this already inserted data, change the order in the combobox. For exampled column UNID descending.

thanks again / Henrik

--- neteject.com - Internet Solutions ---
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top