logo       

RE: Sorting a Listbox in C#: msg#00063

Subject: RE: Sorting a Listbox in C#
Kieth,
Looks like your trying to sort an auto increment field from the name i.e.
keyfield which is probably an int. But you?re your code says it's a string
and so sort is sorting on an ASCI value. Try something along these lines. 

Int32[] myArray = new Int32[myDv.Rows.count];

Int32 count = 0;

Foreach(DataRowView myDv in myDv.rows)
{
        myArray[count] = int.parse("keyField");

        count++;
}

I'm sure this has all kinds of syntax errors and I just typed it out real
quick, but the above should show you if your DataView sort now works if you
step through it.

Peter Ehli

________________________________________
From: Keith R. Pinster [mailto:keith.pinster@xxxxxxxxx] 
Sent: Monday, December 13, 2004 4:38 PM
To: padnug@xxxxxxxxxxxxxxx
Subject: [padnug] Sorting a Listbox in C#


OK, I must be doing something really stupid.  I have a listbox that I 
am trying to pupulate from a sorted view, but I can't get it to 
work.  Here is the code that I'm using:

DataView myDV = new DataView(dsFieldList.Tables[0]);
myDV .Sort = "KeyField";
Listbox1.DisplayMember = "FieldName1";
Listbox1.ValueMember = "KeyField";
Listbox1.DataSource = myDV ;

But my Listbox1 seems to be populated in a random order.  What the 
heck am I doing wrong?

Thanks
KRP










------------------------ Yahoo! Groups Sponsor --------------------~--> 
$4.98 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/Q7_YsB/neXJAA/yQLSAA/dpFolB/TM
--------------------------------------------------------------------~-> 

 


<Prev in Thread] Current Thread [Next in Thread>