编辑模式下 DataGridView C# 行中的默认值
我有一个程序,用于使用网格视图将值输入到数据库中。网格视图填充了来自数据集的“空”结果,该数据集从我想要的表中查询该数据库。这将用我想要的正确列填充网格(即带有来自数据库中某个表的空行的网格)。当您填写列时,我会获取数据并手动更新数据库。
我如何使用 gridview 的基本示例:
this.fullUutDataTableAdapter.Fill(this.dalsaUutDataSet.ResultsFullUut);
DataView dv = this.dalsaUutDataSet.ResultsFullUut.DefaultView;
Grid_modify.DataSource = dv;
foreach(DataGridViewRow dr in Grid_modify.Rows)
{
dr.Cells["YieldID"].Value = -1;
}
但是,我希望某些列具有默认值。我尝试更改列的默认值,但您无法更改该属性,只能“获取”它。或者,我尝试解析空网格中的行并填充值。当网格最初加载时(值显示在适当的位置),这可以正常工作。然而,当我进入编辑模式时,这些值就变得一清二楚。
接下来,我尝试使用一些 RowEdit 事件,并尝试在进入编辑模式时填写值,但是,当您进入和离开编辑模式时,这会导致问题。似乎是一种更复杂、更混乱的方式来做看似必要的事情。
所以问题实际上是,在某些列中使用默认值填充网格视图的最佳方法是什么?
我更喜欢“最干净”的解决方案。然而,我认识到事情并不总是这样......
提前感谢您的帮助!干杯。
I have a program that I use to enter values into a database using a gridview. The gridview is populated with an 'empty' result from a DataSet that queries that database from the table I want. This fills the grid with the proper columns that I want (ie. a grid with an empty row from a certain table in a db). When you fill in the columns, I take the data and manually update the db.
Basic example of how I use the gridview:
this.fullUutDataTableAdapter.Fill(this.dalsaUutDataSet.ResultsFullUut);
DataView dv = this.dalsaUutDataSet.ResultsFullUut.DefaultView;
Grid_modify.DataSource = dv;
foreach(DataGridViewRow dr in Grid_modify.Rows)
{
dr.Cells["YieldID"].Value = -1;
}
However, I want to have certain columns to have Default Values. I have tried changing the column's default value, but you cannot change the property, only 'GET' it. Alternatively, I tried parsing through the rows in the empty grid and filling in the values. This works fine when the grid loads up initially (values show up in proper places). HOWEVER, when as soon as I enter edit mode these values clear to nothing.
NEXT, I tried using some of the RowEdit Events and tried filling in values when edit mode is entered, however, this causes problems when you enter and leave edit mode. Seems to be a more complicated and messy way of doing things that seemingly necessary.
So the question really is, what is the best way to fill a gridview with default values in certain columns?
I would prefer the "cleanest" solution possible. However, I recognize that things don't always work out that way.....
Thanks for your help in advance! Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看一下:如何指定默认值对于 DataGridView
Take a look at this: How To Specify Default Values for DataGridView