我嘗試訂購我的datagridview,但不能。在網絡上,我發現和修改這個:訂購datagridview與linq降序
List<DataGridViewRow> q = (from item in dataGridView1.Rows.Cast<DataGridViewRow>()
orderby item.Cells[0].Value descending
select item).ToList<DataGridViewRow>();
但它不工作,因爲我不知道如何向此列表分配給我的datagridview的數據源。
也許,這不是正確的形式。在其他項目中,我將數據放在列表中的datagridview中,然後在列表中執行linq查詢,這是行得通的。在datagridview中如何?如果你決定使用LINQ(也許更復雜的順序,或者操縱在一些其他的方式中的數據),這將會是最好行事原始來源
dataGridView1.Sort(dataGridView1.Columns[0], ListSortDirection.Descending);
:
謝謝你!它的作品 – WFgo
@WFgo,你好,歡迎:) –