编辑模式期间行中的 DataGridView C# 默认值 [英] DataGridView C# Default Values in Rows During Edit Mode

查看:32
本文介绍了编辑模式期间行中的 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# 默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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