C#.net中datagridview内的组合框 [英] combo box inside datagridview in C# .net

查看:451
本文介绍了C#.net中datagridview内的组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨Frds,
我在datagridView内有组合框...当窗体本身加载时,我正在加载组合框值...通过以下代码...我需要在组合框中添加"SELECT" ...并且"SELECT"应显示在首先将组合框...如何操作.


datatable dt = datatable_value();
如果(dt.Rows.Count> 0)
{
datagrid_Column1.DataSource = dt.DefaultView;
datagrid_Column1.DisplayMember ="Company_Name";
datagrid_Column1.ValueMember ="Company__Id";
}

Hi Frds,
I have Combo box inside datagridView...While Form load itself i am loading the combo box values...By below codes...I need to add "SELECT" to the combo box...and "SELECT" should display in the combo box first...How to do it.


datatable dt=datatable_value();
if (dt.Rows.Count > 0)
{
datagrid_Column1.DataSource = dt.DefaultView;
datagrid_Column1.DisplayMember = "Company_Name";
datagrid_Column1.ValueMember = "Company__Id";
}

推荐答案

^ ]签出此链接

[^]checkout this link


您的疑问词使您难以理解:Pageload表示ASP.NET,但带有标签,组合框,datagridview的话说的是winforms!
您共享的代码属于Grid!
:doh:


1.简单的方法:在查询本身中在数据库级别进行处理!
在组合框中查询数据的示例:
Your question words confuses on what you are working on: Pageload says ASP.NET but tag, combobox, datagridview words says winforms!
Code you shared is of Grid!
:doh:


1. Easy way: Handle at DB level in query itself!
example query for data in combobox:
SELECT cbValue, cbText FROM myTable
UNION
SELECT '0' as cbValue, 'Select combobox' as cbText
ORDER BY cbValue



2.其他方式:将选择添加到检索到的数据表中,然后将其绑定到组合框.使用索引"0"添加选择项以将其显示在顶部.



2. Other way: Add the select to the datatable retrieved and then bind it to the combobox. Use Index ''0'' to add the select to show it at the top.


这篇关于C#.net中datagridview内的组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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