logo       

Re: Sorting a Listbox in C#: msg#00066

Subject: Re: Sorting a Listbox in C#

Thanks for responding Peter.  You are absolutely right in that it is 
sorting Alpha instead of Numeric.  

However, I'm not sure how putting the numeric field into an array is 
going to solve the problem.  Especially when the array doesn't 
include the field that I want to display.

Another issue is that the DataView object doesn't seem to have a 
Rows collection associated with it.  I know I can pull it directly 
from the root table, but we still have that darned sorting issue.

KRP

--- In padnug@xxxxxxxxxxxxxxx, "Peter Ehi" <pehli@xxxx> wrote:
> Code Addendum :-)
> 
> myArray[count] = Int32.parse(myDv.rows[count]);
> 
> ________________________________________
> From: Peter Ehi [mailto:pehli@xxxx] 
> Sent: Monday, December 13, 2004 9:31 PM
> To: padnug@xxxxxxxxxxxxxxx
> Subject: RE: [padnug] 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@xxxx] 
> 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
> ADVERTISEMENT
> 
> 
> 
> 
> ________________________________________
> Yahoo! Groups Links
> ? To visit your group on the web, go to:
> http://groups.yahoo.com/group/padnug/
>   
> ? To unsubscribe from this group, send an email to:
> padnug-unsubscribe@xxxxxxxxxxxxxxx
>   
> ? Your use of Yahoo! Groups is subject to the Yahoo! Terms of 
Service.





------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/dpFolB/TM
--------------------------------------------------------------------~-> 

 


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