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

Grid adding new rows

I'm evaluating the databoundgrid for use in an invoice generator. I have 3/4 of it working just as planned however there are a couple of things I can't figure. Not sure if this counts as a specific usage issue. I create a datatable in code with 1 row as a start, I then bind my grid to this. 3 of the columns have default values set within the datatable. At run time, I see the grid with my initial default row and a second blank row beneath it[1]. As soon as I tab off of the first column a 3rd row is added to the grid (with its default values from the datatable set) in between the two existing rows[2]. Basically I don't want this to happen until the user tabs off the final column to wrap round to a new row. I'm assuming that due to the default values showing that it's actually adding a second row to the datatable. How can I prevent this until the user tabs off of the last column? If there is only 1 item to be invoiced then the second row is not needed. Also if things go to plan then I will be adding rows to that datatable from different forms (sales staff can add items straight from our product form or input manually) so if the user adds one item from the invoice form and then goes and adds one from a product page I'm going to end up with a blank row in the middle of my datatable. [1,2]See www.dreamwolf.net/grid.htm for example screenshot Even more preferable would be for the second row not to show in the first place but since thats not affecting the datatable I'm not that worried, thats just asthetics. Thanks in advance, so far the grid is looking perfect :) Morkai

3 Replies

AD Administrator Syncfusion Team April 29, 2003 08:09 PM UTC

In the grid, the default values come from GridDataBoundGrid.Model.ColStyles[col].CellValue. So, in your formload, if you have the DataTable.Columns[col].DefaultValue's, you could move them into the ColStyles. Here is a little sample showing how you might do it. The sample starts with 10 rows, but works ok if you just start with 1 row. Maybe something like this will work for you. But if you want to dynamically set the values without relying on the defaults in the DataTable, try handling CurrentCellMoved.

private void gridDataBoundGrid1_CurrentCellMoved(object sender, Syncfusion.Windows.Forms.Grid.GridCurrentCellMovedEventArgs e)


	GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;

	if(cc.RowIndex == this.gridDataBoundGrid1.Model.RowCount)



		this.gridDataBoundGrid1[cc.RowIndex , 1].Text = "defaultcol1";

		this.gridDataBoundGrid1[cc.RowIndex  , 2].Text = "defaultcol2";



TG Trevor Guy April 30, 2003 11:04 AM UTC

Hey Clay, thanks for the quick response but I think we got our wires crossed somewhere. It's not the default values I'm having an issue with but the actual adding of a new row. At present it visibily adds a new row to the grid when I tab off of the very first column. I would prefer it to add that row when the user tabs off of the last column. (I have the grid wrapround already set) Apologies, my mentioning of default values was in regard to the fact that I was assuming that because the default values I was setting in my underlying datatable were showing when it added this row, (as opposed to the completely blank row that is always at the bottom of the grid. See the screenshots I linked in the first message if you can't picture what I'm talking about.) that it was in fact creating and adding the row to my underlying datatable. I don't want this to happen unless the user specifically tabs off of the very last column in the grid with the strict intention of moving to the next row to add another item. (our current system already works like this and they are very used to it) Hope that makes more sense. Thanks again Morkai

AD Administrator Syncfusion Team April 30, 2003 08:28 PM UTC

If you set the gridDataBoundGrid1.Model.Options.WrapCellBehavior = GridWrapCellBehavior.NextControlInForm , there is an event that fires as you tab off the bottom right cell. If you catch this event, you can add a row to the underlying datasource. Then refreshing the grid will show an empty row. Attached is a little sample.

Live Chat Icon For mobile
Up arrow icon