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.
Unfortunately, activation email could not send to your email. Please try again.

GDBG new row

Thread ID:

Created:

Updated:

Platform:

Replies:

12998 Apr 17,2004 03:53 AM Apr 19,2004 02:05 AM Windows Forms 3
loading
Tags: GridControl
Serban Alexandru Florian
Asked On April 17, 2004 03:53 AM

Hello everybody! I have the following situation: I have a GDBG bound to a datatable in a dataset. Not all the datatable columns are bound in the grid. The first column has another datasource and the cell type is a Combobox. When adding a new row in the grid, the user selects a value in the combobox and a new row is created. What I would like to do is tho access this new row and set some column values based on the value selected in the combo and also some other values representing constraints. How can I access this now row before it is added to the table so all the constraints are satisfied and the values based on the combo selection are set? Thank you!

Administrator [Syncfusion]
Replied On April 17, 2004 09:31 AM

You can try handling CurrentCellStartEditing, and directly add the new row to the DataSource (not letting teh grid do it). This way, you can access the new datarow and add your defaultvalues.
private void gridDataBoundGrid1_CurrentCellStartEditing(object sender, CancelEventArgs e)
{
	GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
	if(cc.RowIndex == this.gridDataBoundGrid1.Model.RowCount)
	{
		//dt is a DataTable that is the grid''s DataSource
		DataRow dr = this.dt.NewRow();
		dr["Col2"] = "someDefaultvalue";
		this.dt.Rows.Add(dr);
	}
}

Satish
Replied On April 18, 2004 11:50 PM

Clay, Is this works for even for coping and pasting the multiple rows.. Thanks Satish >You can try handling CurrentCellStartEditing, and directly add the new row to the DataSource (not letting teh grid do it). This way, you can access the new datarow and add your defaultvalues. > >
>private void gridDataBoundGrid1_CurrentCellStartEditing(object sender, CancelEventArgs e)
>{
>	GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
>	if(cc.RowIndex == this.gridDataBoundGrid1.Model.RowCount)
>	{
>		//dt is a DataTable that is the grid''s DataSource
>		DataRow dr = this.dt.NewRow();
>		dr["Col2"] = "someDefaultvalue";
>		this.dt.Rows.Add(dr);
>	}
>}
>

Administrator [Syncfusion]
Replied On April 19, 2004 02:05 AM

No, CurrentCellStartEditing is only hit when your user types into the grid. If you want to want to handle adding rows when you paste, you will have to handle the Model.ClipboardPaste event.
private void gridModel_ClipboardPaste(object sender, GridCutPasteEventArgs e)
{
DataObject data = (DataObject) Clipboard.GetDataObject();
if(data.GetDataPresent(DataFormats.Text))
{
	string s = (string)data.GetData(DataFormats.Text);
	string[] rows = s.Split(new char[]{''\n''});
	int numRows = rows.GetLength(0);
	if(numRows > 0 && rows[numRows - 1].Length == 0)
		numRows--; //remove extra empty row if present
	int numCols = 0;
	if(numRows > 0)
	{
		string[] cols = rows[0].Split(new char[]{''\t''});
		numCols = cols.GetLength(0);
		while(this.gridDataBoundGrid1.CurrentCell.RowIndex + numRows 
			> this.gridDataBoundGrid1.Model.RowCount)
		{
			DataRow dr = dt.NewRow();
			dr["Col2"] = "someDefaultvalue";
			dt.Rows.Add(dr);
		}
	}
}
}

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.

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.

;