Live Chat Icon For mobile
Live Chat Icon

How do I set default values for new rows in my datagrid

Platform: WinForms| Category: Datagrid

You use the DataColumn.DefaultValue property to provide default values for new rows. You access this property through the DataTable associated with the DataGrid,

[C#]
	this.dataGrid1.DataSource = this._dataSet.Tables['orders'];
	....
	....
	this._dataSet.Tables['Orders'].Columns[1].DefaultValue = 'CustID';   // default value for column 1
	this._dataSet.Tables['Orders'].Columns['OrderDate'].DefaultValue = DateTime.Now;  // default value for OrderDate column

[VB.NET]
	Me.dataGrid1.DataSource = Me._dataSet.Tables('Orders')
	....
	....
	Me._dataSet.Tables('Orders').Columns(1).DefaultValue = 'CustID'   ’ default value for column 1
	Me._dataSet.Tables('Orders').Columns('OrderDate').DefaultValue = DateTime.Now   ’ default value for OrderDate column

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.