C#Datagridview与DatagridComboBoxColumn

编程入门 行业动态 更新时间:2024-10-17 11:34:45
本文介绍了C#Datagridview与DatagridComboBoxColumn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在form1上,我有datagridview,在代码中我添加了列类型DataGridComboboxColumn和接下来的3列带有普通文本的内容. 我像这样填充组合框:

Hi, On form1 I have datagridview, in code i add column type DataGridComboboxColumn and next 3 columns with normal text. Combobox i fill like this:

foreach (DataRow row in ds.Tables["tbluslugi"].Rows) { nazwa.Items.Add(row["Nazwa"].ToString()); }

我使用事件dataGridView1_CurrentCellDirtyStateChanged,当我在组合框中选择某个值后,此事件就是启动.但是,当我想找回所选择的价值时,value = false.值=当我转到下一行时的选定值,在这种情况下,我必须使用事件CellEndEdit,但是当我从组合框中选择某物而没有任何反应时,它看起来很糟糕. 我想要的是?我想要当我选择valuse形式组合框时(不要等待下一行),它正在数据库中查找此值,取回数据并将其放在此行的空单元格中. 我还有一个问题,如何在datagridcombobox中设置默认项?

I use event dataGridView1_CurrentCellDirtyStateChanged, after when i choose in combobox some value this event is Launch. But when i want get back value what was chosen, value = false. Value = chosen value when i go to next row and i this case i have to use event CellEndEdit but it`s look bad, when i choose somthing from combobox and nothing happend. What i want? I want when i choose valuse form combobox (don`t wait to go next row) it`s looking in database this value, get back data and put it in empty cells in this row. I have another quastion, how to make default item in datagridcombobox ?

推荐答案

我想我知道您希望在选择之后更改文本单元格中的值在组合框中. 如果是这种情况,请使用EditingControlShowing事件来设置组合框更改事件. 像这样 I think I understand that you want the values in the text cells to change after a selection is made in the combo box. If this is the case, use the EditingControlShowing event to setup the combo boxes change event. Like this private void dataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if(dataGridView.CurrentCell.ColumnIndex == 1) { ComboBox cmb = (ComboBox)e.Control; cmb.SelectedValueChanged += new EventHandler(cmb_SelectedValueChanged); } } void cmb_SelectedValueChanged(object sender, EventArgs e) { //Update your 3 text fields here }

希望对您有帮助

Hope this helps

更多推荐

C#Datagridview与DatagridComboBoxColumn

本文发布于:2023-11-10 16:20:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1575871.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Datagridview   DatagridComboBoxColumn

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!