我有数据库,我填写DataGridView。排序DataGridView不为我工作
我尝试通过按赫德这样对我的DataGridView排序:
private void dataGridView1_ColumnHeaderMouseClick(object sender,DataGridViewCellMouseEventArgs e)
{
SortOrder ss = dataGridView1.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection;
string strColumnName = dataGridView1.Columns[e.ColumnIndex].Name;
label8.Text = "Column: " + strColumnName + " - " + "sort order: " + ss.ToString();
if (strColumnName == "Column9")
{
if (ss == SortOrder.Ascending)
{
A_table = "Tmp_Kabat_SfiraTbl";
SQL = "SELECT Color,Line,Makat,Des,sQty,sNewQty,CountBy_Name,UserName,TermNum,NewQty,Qty from " + A_table + " order by NewQty asc";
}
else if (ss == SortOrder.Descending)
{
A_table = "Tmp_Kabat_SfiraTbl";
SQL = "SELECT Color,Line,Makat,Des,sQty,sNewQty,CountBy_Name,UserName,TermNum,NewQty,Qty from " + A_table + " order by NewQty desc";
}
dsView = new DataSet();
adp = new OleDbDataAdapter(SQL, Main.Conn);
adp.Fill(dsView, A_table);
adp.Dispose();
dataGridView1.DataSource = dsView.Tables[A_table].DefaultView;
this.dataGridView1.ClearSelection();
}
}
其作品只有一次,它不从ASC变化降序排序
什么可能是问题吗?
同样的问题:( – Gold
请参阅我的编辑答案。 –
感谢您的帮助,但我需要抓住列和排序类型 - 并从中进行查询。你能用我的示例代码来帮助我吗? – Gold