Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I set default values for new rows in a 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#]

dataGrid1.DataSource = dataSet.Tables[ "orders" ];

// default value for column 1
dataSet.Tables[ "Orders" ].Columns[ 1 ].DefaultValue = "CustID";

// default value for OrderDate column
dataSet.Tables[ "Orders" ].Columns[ "OrderDate" ].DefaultValue = DateTime.Now;

Contributed from George Shepherd's Windows Forms FAQ



Page view counter