vb.net - DataGridViewRow numerically order -
how can sort datagridviewrow numerically order?
my code:
dim name new list(of string) dim price new list(of integer) x = 0 math.max(name.count, price.count) if x < name.count andalso x < price.count dim row string() = new string() {name(x), price(x)} datagridview1.rows.add(row) end if next
price row example:
1345 1533 4555 6744
you've got them 2 separate lists... i'll take leap , make assumption need keep source data in format... having them in 2 lists you've got dependency on positions. use sortable collection pair them
e.g.
imports microsoft.visualbasic imports system.collections.generic imports system.data.linq dim name new list(of string) dim price new list(of integer) dim sortable new list(of keyvaluepair(of string, integer)) 'your checking weren't going past last pair odd 1 x = 0 math.min(name.count, price.count) - 1 'pair them can sort them not having try match between 2 lists sortable.add(new keyvaluepair(name(x), price(x))) next 'now can sort sortable = (from item in sortable order convert.toint32(item.key) select item).tolist() 'now stick in grid view, might able base grid view on 'datagridview1.datasource = sortable 'datagridview1.databind() 'depends on how defined/configured, 'but let return original code.... each kvp keyvaluepair(of string, integer) in sortable dim row string() = new string() {kvp.key, kvp.value.tostring("$0.00")} datagridview1.rows.add(row) next
Comments
Post a Comment