在datagridview中对DataGridViewComboBoxColumn中的数据进行排序

时间:2013-12-18 17:58:13

标签: c# datagridview

DataGridViewComboBoxColumn Column2 = new DataGridViewComboBoxColumn();
Column2.DisplayStyleForCurrentCellOnly = true;
Column2.FillWeight = 98.41095F;
Column2.FlatStyle = System.Windows.Forms.FlatStyle.System;
Column2.HeaderText = "نام کالا";
Column2.Name = "Column2";
Column2.Resizable = System.Windows.Forms.DataGridViewTriState.False;
//Column2.Sorted = true;
Column2.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
Column2.ValueMember = "Name";

gridsabtekala.Columns.AddRange(new DataGridViewColumn[] { Column2 });
var v = (from a in linqedit.KalaNames
        select a.Name).ToList();
Column2.DataSource = v;

1 个答案:

答案 0 :(得分:0)

使用LINQ OrderBy

   var v = (from a in linqedit.KalaNames
            select a.Name).OrderBy(n => n.Name).ToList();
   Column2.DataSource = v;