如何在数据网格视图中绑定comboxcell选择的值 [英] how to bind comboxcell selected value in datagridview

查看:81
本文介绍了如何在数据网格视图中绑定comboxcell选择的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我创建了一个combox,并在用户单击
时将其添加到datagridview 特定的单元格组合框将显示在该单元格中.这里的问题是
从combox选择值后,如果我移到下一个单元格,则选择的值
将消失.我要将所选值存储到datagridview单元中.
我的代码是

 公共 ComboBox combobox2 =  ComboBox();
私有 无效 hmloadingpage1_Load(对象发​​件人,EventArgs e)
{
   
   combobox2.Hide();
   dataGridView1.Controls.Add(combobox2);

}

私有 无效 dataGridView1_CellDoubleClick(对象发​​件人,DataGridViewCellEventArgs e)
{
    .combobox2.Location =  .dataGridView1.GetCellDisplayRectangle(e.ColumnIndex,e.RowIndex, true ).位置;
            .combobox2.SelectedValue =  .dataGridView1.CurrentCell.Value;
            .combobox2.Show();
       } 




如果有人知道如何存储所选值,请帮帮我.

解决方案



我使用数据网格的方式是将单元格的属性设置为组合框,然后将内容添加到集合中.我相信您也可以为此使用绑定源.

当用户从组合框中选择时,该值将保持显示.如果需要设置默认值,则需要使用Text属性,然后如果要保存数据,则需要将单元格引用为datagridname.row [index ] .cell [index] .value并将其转换为所需的数据类型.

希望对您有所帮助.


hi i have created a combox and add it to the datagridview when the user click
the particular cell combobox will be displayed in that cell.the problem here is
after selecting the value from combox and if i move to next cell the selected value
will be disappear .i want to store the selected value to the datagridview cell.
and my code is

public  ComboBox combobox2 = new ComboBox();
private void hmloadingpage1_Load(object sender, EventArgs e)
{
   
   combobox2.Hide();
   dataGridView1.Controls.Add(combobox2);

}

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
   this.combobox2.Location = this.dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Location;
           this.combobox2.SelectedValue = this.dataGridView1.CurrentCell.Value;
           this.combobox2.Show();
       }




if anyone have any idea how to store the selected value help me.
thank''s in advance

解决方案

Hi,

The way I used the data grid was to set the property of the cell as combo box and add the contents in the collections. I believe you could also use a binding source for this.

When the user select from the combo box the value remains displayed.If you need to set a default value you need to use the Text property and if you then want to save your data you need to refer to the cell as datagridname.row[index].cell[index].value and convert this to your desired datatype if necessary.

I hope this helps.


这篇关于如何在数据网格视图中绑定comboxcell选择的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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