Sort C# ListBox Items -
i'm using c# adapter method, add elements list , after call list fill listbox, here button that:
private void button1_click(object sender, eventargs e) { listcustomers.items.clear(); list < customer > customers = customerlist.getcustomers(); list < customersaldo > customerssaldo = customerlistsaldo.getcustomers(); int total = 0; int totalcustomer = 0; foreach(customer customer in customers) total++; listcustomers.items.clear(); totalcustomer = total; int x = totalcustomer; foreach(customersaldo customer2 in customerssaldo) { if (x >= 1) { listcustomers.items.add("costumer id # " + x + " is: " + customer2.saldo); x--; } } }
this get, it's ok want know if exists way example:
costumer #1 saldo...
costumer #2 saldo...
costumer #3 saldo...
if see code have variable x
, variable total number of costumers, think sort has start variable, don't know how it, can do?
reverse list , start counting untill reach end:
//reverse list customerssaldo.reverse(); //add new items for(int = 0; < customers.count; i++) listcustomers.items.add(string.format("costumer id # {0} is: {1}", (i+1).tostring(), customerssaldo[i].saldo);
Comments
Post a Comment