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

查看:593
本文介绍了在DataGridView的行C#中的默认值在编辑模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我使用的值输入到使用一个GridView的数据库的程序。在GridView填充了来自查询从我想要的表数据库数据集空的结果。这填满了,我想(即从某个表在数据库中的空行网格)的正确列网格。当您在填写栏,我取数据和手动更新分贝。

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.

我如何使用gridview的基本例如:

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;
}



不过,我想有一定的列有默认值。我试图改变列的默认值,但你不能改变的财产,只有'GET'吧。另外,我试图通过解析排在空网格,并在值填写。当电网最初加载了(值适当的地方显示出来)这工作得很好。然而,当我只要一进入编辑模式,这些数值清楚罢了。

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.

接下来,我尝试使用一些RowEdit事件和值试图填充时编辑模式进入,不过,这将导致当你进入和离开编辑模式的问题。似乎做的事情,看似必要的更加复杂和混乱的方式。

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.

所以,真正的问题是,什么是填补具有默认值的GridView的最佳途径某些列?

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.

推荐答案

看看这个:的如何指定默认值的DataGridView

这篇关于在DataGridView的行C#中的默认值在编辑模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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