Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

help with sorting DataGridView - pressing on Heder

$
0
0

hi

i have database that i fill on DataGridView.

i have NewQty = int   and sNewQty = string fileds.

i try to sort my DataGridView by pressing on Heder like this:

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();
        }

its works only one time, it dont change from asc  to  desc  sorting

what can be the problem ?


Viewing all articles
Browse latest Browse all 12583


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>