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. Image for the cookie policy date
close icon

GDBG new row

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!

3 Replies

AD Administrator Syncfusion Team April 17, 2004 01:31 PM UTC

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


SA Satish April 19, 2004 03:50 AM UTC

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


AD Administrator Syncfusion Team April 19, 2004 06:05 AM UTC

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[]{''''});
	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);
		}
	}
}
}

Loader.
Live Chat Icon For mobile
Up arrow icon