根据后端(数据库)值绑定组合框值(在datagridview内) [英] binding the combobox value(inside the datagridview) based on backend(database) value

查看:76
本文介绍了根据后端(数据库)值绑定组合框值(在datagridview内)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i在数据网格视图中有一个组合框(suresh,ramesh,naresh)。



在我的数据库中保存ramesh。



正确读取但我不知道如何绑定组合框(给selectedindex = 1)。



任何机构都可以解决这个问题。





提前感谢.... ......

解决方案

  string  str =  选择id,来自tbl的名称; 
// 使用sql-connection和数据适配器获取数据表
da。补(DT);
combobox1.Datasource = dt;
combobox1.DisplayMember = name;
combobox1.ValueMember = id;
combobox1.Refresh();







网格视图

 If(dgv.currentcell.ColumnIndex ==  2  //  第二个是组合框列 
{
datagridViewComboboxCell combobox1 = Directcast(dgv.currentcell,datagridViewComboboxCell);
// 现在使用上面的代码
}





快乐编码!

:)


转到 ItemDataBound gridview事件并找到 ComboBox 控件并设置 DataSource DataTextField DataValueField 正如Aarti在解决方案2中所述。







--Amit


最后我做了这个



< pre lang =cs> if (datagridview1.Rows.Count!= 0
{
for int i = 0 ; i < datagridview1.Rows.Count; i ++)
{

datagridview1.Rows [i] .Cells [ Type ]。值= DatabaseValue;

}

}


hi all,

i have a combobox having items(suresh,ramesh,naresh) inside the datagridview.

in my database saving ramesh.

reading correctly but i don't know how can i bind the combobox(giving selectedindex=1).

can any body solve this.


thanks in advance..........

解决方案

string str="select id,name from tbl";
//fetch datatable using sql-connection and data-adapter
da.fill(dt);
combobox1.Datasource=dt;
combobox1.DisplayMember="name";
combobox1.ValueMember="id";
combobox1.Refresh();




for grid view

If (dgv.currentcell.ColumnIndex==2) //2nd is combobox column
{
   datagridViewComboboxCell combobox1 = Directcast(dgv.currentcell,datagridViewComboboxCell);
   //   Now use above code here 
}



Happy Coding!
:)


Go to the ItemDataBound event of gridview and find your ComboBox control and set the DataSource, DataTextField and DataValueField as Aarti said in Solution 2.



--Amit


Finally i did this

if (datagridview1.Rows.Count != 0)
  {
      for (int i = 0; i < datagridview1.Rows.Count; i++)
      {

          datagridview1.Rows[i].Cells["Type"].Value = "DatabaseValue";

      }

  }


这篇关于根据后端(数据库)值绑定组合框值(在datagridview内)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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