DataGridViewComboBoxColumn值更改不改变要修改的RowState [英] DataGridViewComboBoxColumn value change not changing RowState to modified

查看:370
本文介绍了DataGridViewComboBoxColumn值更改不改变要修改的RowState的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在datagridview中添加了一个查找组合框。任何更改为现有行或添加新行将在RowState中的值更改为已更改或已添加。除了更改组合框中的值。保存时,RowState保持不变。

I have added a lookup combobox to my datagridview. Any changed to an existing row or adding a new row changed the value in RowState on save to Modified or Added. except changing a value in the combobox. On save, the RowState remains as unmodified.

我用于添加组合框的代码是。

the code i use to add the combobox is.

 DataGridViewComboBoxColumn cbQualification = new DataGridViewComboBoxColumn();
            cbQualification.HeaderText = "Course Code";
            DataSet  myDataSet = GetData.GetCoursesData();
            cbQualification.DataSource = myDataSet.Tables[0];
            cbQualification.DisplayMember = "Code";
            cbQualification.ValueMember = "ID";
            cbQualification.DataPropertyName = "QualID";
            grdPersonQuals.Columns.Insert (1,cbQualification);

保存事件使用代码。

 grdPersonQuals.BindingContext[grdPersonQuals.DataSource, grdPersonQuals.DataMember].EndCurrentEdit();
            foreach (DataRow row in dsPersonQuals.Tables[0].Rows)
            {
                object x = row.RowState;
            }


推荐答案

我猜测焦点当您点击保存按钮时仍在您的组合框列中?我一直调用DataGridView的EndEdit方法来触发更新数据源。

I'm guessing the focus is still in your combobox column when hitting your save button? I've always called the DataGridView's EndEdit method to trigger updating the datasource.

所以在你的保存按钮事件中

So in your save button event

grdPersonQuals.EndEdit();

您正在绑定上下文中调用它,但我相信您需要在网格上调用它所以它将网格中的更改推送到它的数据源。

You are calling it on the binding context, but I believe you need to call it on the grid itself so it pushes the changes in the grid down to it's datasource.

这篇关于DataGridViewComboBoxColumn值更改不改变要修改的RowState的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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