如何使用C#在DataGrid视图中显示组合框的选定值 [英] How I can display selected value from combobox in datagrid view using c#

查看:77
本文介绍了如何使用C#在DataGrid视图中显示组合框的选定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
我有3列名称,log_no和国家/地区
我想从组合框选择国家时显示相关数据名称和log_no"
在datagridview上
等待您的帮助

hi
i''ve 3 columns name, log_no & country
i want when choose country from combobox show the related data "name & log_no"
on datagridview
wait ur help

推荐答案

select * from tablename where country=combobox.selectedItem



使用此查询在组合框的选择更改事件中绑定datagridview



use this query to bind datagridview in selection changed event of combobox


类似于以下内容.包括适当的连接,并修改表名称和与您的项目相对应的对象名称.

Something like the following. Include the proper connection and modify the table name and the object names corresponding to your project.

            SqlCommand command = new SqlCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            DataTable dt = new DataTable();
            
            //command.Connection = connection;
            command.CommandText = @"
SELECT  a.Name,
        a.Log_No
FROM    Table   a
WHERE   a.Country = :country";
            command.Parameters.AddWithValue("country", cmbCountry.Text);
            da.SelectCommand = command;
            da.Fill(dt);
            command.Dispose();
            dataGridView1.DataSource = dt;


这篇关于如何使用C#在DataGrid视图中显示组合框的选定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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