DataGridView C# Default Values in Rows During Edit Mode(编辑模式期间行中的 DataGridView C# 默认值)
问题描述
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.
Take a look at this: How To Specify Default Values for DataGridView
这篇关于编辑模式期间行中的 DataGridView C# 默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:编辑模式期间行中的 DataGridView C# 默认值
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01