We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Initializing hidden fields

Thread ID:

Created:

Updated:

Platform:

Replies:

16352 Jul 13,2004 01:59 PM UTC Jul 14,2004 01:21 PM UTC WinForms 4
loading
Tags: GridControl
Eddy Poullet
Asked On July 13, 2004 01:59 PM UTC

Hi, Which event is the best to set value hidden fields (as Timestamp/userId/default values...) in DBGrid when a new row is "edited" ? Thanks Eddy POULLET Brussels

Administrator [Syncfusion]
Replied On July 13, 2004 02:40 PM UTC

There is sort of a chicken and egg problem here. The grid does not actually add the row to the DataSource until you confirm the new row by leaving it. So, if you want to set default values of things that are not in the grid, you have to work around this delay of adding the new row to the DataSource. One way you can do it is to add the new row yourself, not relying on the grid to do it. You can do this in RowEnter. Here is a minimal snippet assuming the DataSource is a Datatable.
private void gridDataBoundGrid1_RowEnter(object sender, GridRowEventArgs e)

{
	if(this.gridDataBoundGrid1.Model.RowCount == e.RowIndex)
	{
		//assumes DataSource is a DataTable
		DataTable dt = (DataTable) this.gridDataBoundGrid1.DataSource;
		DataRow dr = dt.NewRow();
		//populate your new row however you want
		dr[0] = "col0";
		dr[1] = "col1";
		dt.Rows.Add(dr);
	}
}

Eddy Poullet
Replied On July 14, 2004 09:31 AM UTC

Thanks Clay, Until now, I have used the ColumnChanging event of the datatable. >There is sort of a chicken and egg problem here. The grid does not actually add the row to the DataSource until you confirm the new row by leaving it. So, if you want to set default values of things that are not in the grid, you have to work around this delay of adding the new row to the DataSource. > Why doesn''t it exist an event in the dataset/grid like onNewRow or onBeforeEdit? This will a litle easier ! Eddy

Administrator [Syncfusion]
Replied On July 14, 2004 10:33 AM UTC

The grid has the problem of postponing the actual adding of the row. So, if you wanted to set defaluts in the grid, you would likely need to do that prior to the user typing into the new row. But, by default, the new row is not really in the DataTable at this point, and trying to add default values for fields not in the grid would be a problem. The above code works around this problem. If you want to use a DataSource event to manage setting default values (whether they are in the grid or not), you can catch the IBindingList.ListChanged event on the List member of the CurrencyManager. Below are some snippets. I have forwarded your request for a special grid event to try to manage this task to the grid architect to see if this is something we want to do. CurrencyManager cm = (CurrencyManager) this.BindingContext[this.gridDataBoundGrid1.DataSource, this.gridDataBoundGrid1.DataMember]; IBindingList ibl = cm.List as IBindingList; ibl.ListChanged += new ListChangedEventHandler(ibl_ListChanged);
private void ibl_ListChanged(object sender, ListChangedEventArgs e)
{
	if(e.ListChangedType == ListChangedType.ItemAdded)
	{
		DataView dv = sender as DataView;
		dv[e.NewIndex]["col0"] = "aaaaa";
		dv[e.NewIndex]["col1"] = "bbbbb";
	}
}

Eddy Poullet
Replied On July 14, 2004 01:21 PM UTC

Hi Clay, I understand now better the inner working of the DBGrid. Thanks for the help and the support ! Eddy

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;