有货的组合式箱式过滤器 [英] COMBO BOX FILTER FOR STOCK

查看:63
本文介绍了有货的组合式箱式过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为公司创建程序,但是我被卡在股票表格的筛选器中.
我正在使用一个显示SQL中所有库存的数据网格,但是如果我只想查看某些库存,则插入了一个组合框以过滤该数据网格.

请问该怎么办?
一直在为此

I''m creating a program for a company, but I''m stuck on the Filter of the stock form.
I am using a datagrid that display all the stock from SQL but I inserted a combobox to filter the datagrid if I only want to view certain stock.

What should I do please help??
Been strugling with this

推荐答案

苦苦挣扎.然后将查询结果绑定到数据网格.应该是这样的.
In combobox selectedindex changed event take the selectedindex as the variable and execute query depending to this value. Then bind the query result to the datagrid. It should be something like this.
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string query = "SELECT [fields] FROM [TABLENAME] WHERE [SORTFIELD] = " + comboBox1.SelectedIndex;
            GetData(query);
        }
        void GetData(string selectCommand)
        {
            try
            {
                // Specify a connection string. Replace the given value with a
                // valid connection string for the
                // database accessible to your system.
                String connectionString =
                    "Integrated Security=SSPI;Persist Security Info=False" +
                    "Initial Catalog=Northwind;Data Source=localhost";
                // Create a new data adapter based on the specified query.
                dataAdapter = new SqlDataAdapter(selectCommand, connectionString);
                // Create a command builder to generate SQL update, insert, and
                // delete commands based on selectCommand. These are used to
                // update the database.
                SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
                // Populate a new data table and bind it to the BindingSource.
                DataTable table = new DataTable();
                table.Locale = System.Globalization.CultureInfo.InvariantCulture;
                dataAdapter.Fill(table);
                bindingSource1.DataSource = table;
                // Resize the DataGridView columns to fit the newly loaded content.
                dataGridView1.AutoResizeColumns(
                    DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
            }
            catch (SqlException)
            {
                MessageBox.Show("To run this example, replace the value of the " +
                    "connectionString variable with a connection string that is " +
                    "valid for your system.");
            }
        }



不要忘记刷新gridview.



Don''t forget to refresh the gridview.


这篇关于有货的组合式箱式过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆