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.

Grid adding new rows

Thread ID:

Created:

Updated:

Platform:

Replies:

4120 Apr 29,2003 01:14 PM Apr 30,2003 04:28 PM Windows Forms 3
loading
Tags: GridControl
Trevor Guy
Asked On April 29, 2003 01:14 PM

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

Administrator [Syncfusion]
Replied On April 29, 2003 04:09 PM

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.Binder.BeginEdit();


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


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


	}


}



Trevor Guy
Replied On April 30, 2003 07:04 AM

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

Administrator [Syncfusion]
Replied On April 30, 2003 04:28 PM

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.

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.

;