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

Delete Rows in Hieratical Grid

Please help me with this one. I have a hieratical Grid (two tables boun through a relation). Here is the code for creating the "+" link DataGrid: //fill the Data in teh Related Tables this.adptInput.Fill(this.dsInputList, "Input"); this.adptReel.Fill(this.dsInputList, "tblReel"); // //add the relation between the tables // dsInputList.Relations.Add( dsInputList.Tables[0].Columns["iID"], dsInputList.Tables[1].Columns["rInputID"]); dsInputList.Relations[0].RelationName = "Reels_Relation"; // //Set the GridHierarchyLevel in order to obtain the "+" link // GridHierarchyLevel hlInput = gridBinder.RootHierarchyLevel; GridHierarchyLevel hlInput_Reels = gridBinder.AddRelation("Reels_Relation"); Now what I need to do is to be able to delate (remove the rows from the Grid). I have created a Handler for the "Delete" key. Deleting from the main table works perfect. But when I try to delete rows from the related Table, I get the following error: An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.data.dll Additional information: There is no row at position 4. Here is the code that I use for the "Delete" key down event: private void dgInput_CurrentCellKeyDown(object sender, KeyEventArgs e) { if(e.KeyCode == Keys.Delete) { GridRangeInfo range = this.dgInput.Selections.Ranges.ActiveRange; if(range.IsRows) { this.dgInput.Binder.EnableRemove = true; this.dgInput.Binder.RemoveRecords(range.Top, range.Bottom); e.Handled = true; } } } Please help. XP

7 Replies

AD Administrator Syncfusion Team July 2, 2003 01:57 PM UTC

Again, this will be much easier in the 2.0 code base. Here is a sample of how you can go about this now.


AD Administrator Syncfusion Team July 2, 2003 07:27 PM UTC

Wow, this example is great. It has the basic layout of what I've been wanting to do. Now my question to you would be how well does something like this support formulas? Since rows are being inserted in may diffrent places, how would that work? Thanks for the sample code. Javier


AD Administrator Syncfusion Team July 2, 2003 08:18 PM UTC

Formula support requires a FormulaTag object be stored for each formula cell. Since a GridDataBoundGrid does not store cell specific properties other than the cell value (which is managed by the datasource), you must maintain some external data object that stores these FormulaTags. For a simple GDBG, you can use a HashTable with unique ID keys to get around this problem, but with a dynamic hierarchical grid, it would be more difficult. So, supporting formulas in a hierarchical grid would be very difficult. We think the 2.0 release will simplify working with hierarchies. Maybe we can reduce the complexity of using formulas in a hierarchical grid after that release.


XP XP July 3, 2003 07:48 AM UTC

Thanks very much Clay. The code works very nice. I am still having some problems in implementing the delete mechanism on DataSets. Your example uses Lists and it seems I cannot make the code listen to me... If you Clay, or someone else, has 5 minutes to look over me code... Hope it is not to much. Anyway, maybe someone can find the code useful. Just unzip it and place the database in the root of "C:\" Drive. The file containing the delete issue is: FrmInputList.cs. When launchig the application you can get there by clicking on the Input > InputList Menu. Thanks again for everithing!


AD Administrator Syncfusion Team July 3, 2003 08:05 AM UTC

Attached is a DataTable version of te sample (more or less). If you cannot spot the problem in your code, post again and I'll try to look at it.


AD Administrator Syncfusion Team July 3, 2003 03:43 PM UTC

Thanks !!! The code worked perfectly :) You helped me a lot, thanks again.


AD Administrator Syncfusion Team July 3, 2003 05:53 PM UTC

I promise this is the last one :) In fact, the reason for all the questions above was the "control" of the delete process from a hieratical grid. There is a column (found only in the child table) containig a boolean (checkbox in the datagrid). If this value is true I need to cancel the delete process. If the boolean is false, the delete process is allowed. With the substantial help from Clay I have managed to acomplish these 2 tasks. But there is the posibility that the user will delete a row coresponding to the Parent table (a row having the "+" link on it). The delete process shold not be allowed if there is at least one child row coresponding to it that has the boolean value set to "true". So is it posible to evaluate a specific cell value among the child rows and block the delete process? If someone can help me I have the code attached (to get rid of creating such a scenario). Unzip it and place the database in the root of C:\ drive. After you run the code, the grid containing the hieratical levels can be found by clicking on "Input -> Input List" menu. The file having to deal with is FrmInputList.cs. The delete process is fired when the "Delete" Key is pressed, and a row is selected. Thanking you in advance, XP

Loader.
Up arrow icon