Friday, 30 November 2012

ComboBox selectchanged to sort by Gridview




How to get combobox selectchanged Orderby low,High showing DatgridView  inC# WinForm from MS Access Database.


private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

        {
            string selectString = "";
           
            //this.stockTableAdapter.FillBy(this.dB_BillingDataSet.stock);
            System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
            conn.ConnectionString = BillingApplication.Properties.Settings.Default.DB_BillingConnectionString;
            conn.Open();
            if (comboBox1.Text == "Lower")
                selectString = "SELECT product_id,product_quantity FROM stock ORDER BY product_quantity ASC";
            else
                selectString = "SELECT product_id,product_quantity FROM stock ORDER BY product_quantity DESC";
            int id = 0, product_quantity = 0, r = 0;
           int r1 = 0;
            OleDbCommand cmd = new OleDbCommand(selectString, conn);
            OleDbDataReader reader = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())
                {

                    //stock query product id, quantity
                    //product  table just  name  where stock(product id)
                    selectString = "SELECT product_name FROM product WHERE(product_id = " + Convert.ToInt32(reader["product_id"]) + ")";
                    cmd = new OleDbCommand(selectString, conn);
                    OleDbDataReader reader1 = cmd.ExecuteReader();
                
                    string product_name = "";
                    if (reader1.HasRows)
                    {
                        while (reader1.Read())
                        {
                            id = Convert.ToInt32(reader["product_id"]);
                            product_name = reader1["product_name"].ToString();
                            productDataGridView.Rows.Add();
                            productDataGridView.Rows[r1].Cells[1].Value = reader1["product_name"].ToString();
                           
                            r1++;
                           
                        }
                    }
                    //add to grid
                    productDataGridView.Rows.Add();
                    productDataGridView.Rows[r].Cells[0].Value = reader["product_id"].ToString();
                  
                    productDataGridView.Rows[r].Cells[2].Value = reader["product_quantity"].ToString();

                    r++;

                }
            }
            }

When i select a sort by Lower in combobox it showing quantitiy low to High in Ascending order.



When i select a sort by Higher in combobox it showing quantitiy High to Low in Descending Order.



 

SharePoint tenant opt-out for modern lists is retiring in 2019

We're making some changes to how environments can opt out of modern lists in SharePoint. Starting April 1, 2019, we're going to be...