按升序排列的所选项目索引 [英] Selected item Index in Ascending order

查看:168
本文介绍了按升序排列的所选项目索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

插入了DataGridView1,我需要从升序开始的索引。

have inserted DataGridView1 when more then 1 rows selected, I need the Index from Ascending Order.

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim selectedItems As DataGridViewSelectedRowCollection = DataGridView1.SelectedRows
        Debug.Print(DataGridView1.CurrentRow.Index)
        For Each selectedItem As DataGridViewRow In selectedItems
        Next
    End Sub
End Class





所需输出:所有选定的指数应按升序排列它可能在VB.net中的网格中选择



Output required : All the Selected Index should be in Ascending Order, which ever order it might be selected in grid in VB.net

推荐答案

创建一些数据类型,其中包含与排序相关的数据(可能是只有一列或其他东西,具体取决于您的排序标准)加上 - 重要的是 - 目前网格视图中的索引。



收集所有实例来自网格视图的此数据类型,并将所有这些实例放在列表 System.Collections.Generic.List< T> 的实例中,其中 T 应该是这种数据类型:

https://msdn.microsoft.com/en-us/library/6sh2ey19%28v=vs.110%29.aspx [ ^ ]。



然后使用您的比较标准对此列表进行排序:

https://msdn.microsoft.com/en-us/library/w56d4y5z(v = vs.110).aspx [ ^ ]。



-SA
Create some data type which carries the data relevant to sorting (it could be the Value of just one columns, or something else, depending on your sorting criteria) plus — importantly — the index in the grid view at the moment.

Collect all instances of this data type from the grid view and put all these instances in the instance of the list System.Collections.Generic.List<T>, where T should be this data type:
https://msdn.microsoft.com/en-us/library/6sh2ey19%28v=vs.110%29.aspx[^].

Then sort this list using your comparison criteria:
https://msdn.microsoft.com/en-us/library/w56d4y5z(v=vs.110).aspx[^].

—SA


这篇关于按升序排列的所选项目索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆