如果使用DataGrid,如何对行进行排序? [英] How to sort rows if datagrid?

查看:118
本文介绍了如果使用DataGrid,如何对行进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在datagridview中列出了值..我想通过代码对它进行排序,并且也想知道相应的行号...如何也对行号进行排序和查找?

I have listed values in datagridview ..and i want to sort that via code and like to know the respective row number as well... how to sort and find the row number as well??

推荐答案

此处是有关如何对dataGridView进行排序的示例. SortColumn是要排序的列号(从左到右,从零开始).

Here''s an example on how to sort a dataGridView. SortColumn is the Column number you want to sort on (From left to right, starting at zero).

int sortColumn = 0;

if(dataGridView.ColumnCount > sortColumn)
{
  dataGrid.Sort(dataGrid.Columns[sortColumn], System.ComponentModel.ListSortDirection.Ascending);
}



至于获取行号,您可以使用dataGridView行中的索引号



As for getting row numbers you can use the Index number from a dataGridView row

MessageBox.Show(dataGridView.Rows[0].Index.ToString());


我不想在datagridview中显示排序后的列表...我只想获取网格内容及其行的最大值和最小值代码中的任何临时值中的数字都可以说...
maxVal,maxVamRowNo,minVal,MinValRowNo ...
I dont want to show the sorted list in the datagridview ... I only want to get the maximum and minimum value of the grid''s content along with its row number in the code in any temporary values lets say...
maxVal, maxVamRowNo, minVal, MinValRowNo...


另一种方法此处.


这篇关于如果使用DataGrid,如何对行进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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