dataGridView与数据源dataTable同步排序

     private void dataGridView1_Sorted(object sender, EventArgs e)
        {
            string _sortStr = dataGridView1.SortedColumn.Name; //排序列
            SortOrder _so = dataGridView1.SortOrder;            //排序方向
            if (_so == SortOrder.Ascending)
                _sortStr += " asc";
            else
                _sortStr += " desc";
            DataView _dv = dt.DefaultView;
            _dv.Sort = _sortStr;   //排序
            dt = _dv.ToTable();  //将排序后的datatable赋给 dt
        }

你可能感兴趣的:(datagridview)