net中datagridview内的组合框

net中datagridview内的组合框

本文介绍了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";
}

推荐答案


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内的组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 05:07