如何对DataGridViewRow进行排序以进行数字排序?
我的代码:
Dim Name As New List(Of String)
Dim Price As New List(Of Integer)
For x = 0 To Math.Max(Name.Count, Price.Count)
If x < Name.Count AndAlso x < Price.Count Then
Dim row As String() = New String() {Name(x), Price(x)}
DataGridView1.Rows.Add(row)
End If
Next价格行示例:
1345
1533
4555
6744发布于 2014-12-02 12:08:57
你把它们分成两张单子.我要跳一跳,假设你需要把源数据保持在那种格式.将它们放在两个列表中,您目前对它们的位置有依赖关系。因此,使用可排序集合将它们配对。
例如:
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Data.Linq
Dim Name As New List(Of String)
Dim Price As New List(Of Integer)
Dim Sortable As New List(Of KeyValuePair(Of String, Integer))
'Your checking that you weren't going past the last pair was an odd one
For x = 0 To Math.Min(Name.Count, Price.Count) - 1
'Pair them up so you can sort them together not having to try to match between two lists
Sortable.Add(New KeyValuePair(Name(x), Price(x)))
Next
'now you can sort it
Sortable = (From item In Sortable Order By Convert.ToInt32(item.Key) Select item).ToList()
'now stick it in the grid view, You might be able to base the grid view on the
'DataGridView1.DataSource = Sortable
'DataGridView1.DataBind()
'depends on how it is defined/configured,
'but for now let us return to your original code....
For Each kvp As KeyValuePair(Of String, Integer) In Sortable
Dim row As String() = New String() {kvp.Key, kvp.Value.ToString("$0.00")}
DataGridView1.Rows.Add(row)
Nexthttps://stackoverflow.com/questions/27239378
复制相似问题