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

GridGroupingControl(2.0.5.0) Selected Row

My dataset contais two tables are joined by relation. I can''t get selected row in the parent table. Please see the code below. After last line of code variable data = null. why? GridRangeInfoList rangeList = grdQuote.TableControl.Selections.GetSelectedRows(true, false); if( rangeList.Count == 0 ) return; Element element = grdQuote.Table.DisplayElements[rangeList[0].Top]; if( element is GridRecordRow == false ) return; GridRecordRow r = (GridRecordRow) element; Object data = r.GetData();

8 Replies

AD Administrator Syncfusion Team April 24, 2004 11:03 AM UTC

Do you want to really get selected rows, or maybe just the current record? If you do want to just get the current record try this: Record r = grdQuote.Table.CurrentRecord; Object data = r.GetData(); If you need selected records, not sure why r.GetData() returns null. Can you check what grdQuote.Table.Records.IndexOf(r); and grdQuote.Table.UnsortedRecords.IndexOf(r); returns and let me know? The value returned by grdQuote.Table.UnsortedRecords.IndexOf(r) is the original row index in the datasource. You could use that value to look up the datarow in the dataset, e.g. dataTable.Rows[unsortedRecordRowIndex] Stefan


SI Silenter April 26, 2004 08:28 AM UTC

ok. You are correct. But I noticed the folowing: There is a windows timer on my form. and timer ticks every 1 sec. and timer changes data in the dataset which is datasource for grid. I select the one row in the grid. And After timer changes data in the DataSet grdQuote.Table.CurrentRecord returns null. How can I fix it?


SI Silenter April 26, 2004 09:51 AM UTC

Hi againg. grdQuote.Table.CurrentRecord works correctly if selected row is a row of top level table.. But my dataset contains two tables. And if I select a row in the nested table grdQuote.Table.CurrentRecord returns null.


SI Silenter April 26, 2004 10:19 AM UTC

>If you need selected records, not sure why r.GetData() returns null. Please check this sample: http://www.syncfusion.com/support/user/Uploads/SyncGridSelectedRowTest_2011.zip


AD Administrator Syncfusion Team April 26, 2004 11:10 AM UTC

Hi Silenter, change those lines from GridRecordRow r = (GridRecordRow) element; Object data = r.GetData(); to GridRecordRow r = (GridRecordRow) element; Object data = r.ParentRecord.GetData(); Right now GetData is only implemented for Record elements. It makes senseto change our code base such that Element.GetData() will by default call ParentRecord.GetData(). Then such confusion should not happen. But for now you need to call ParentRecord. One more thing: We are gonna release a patch soon and the default for TableOptions.AllowSelection will be GridSelectionFlags.None. So, you will then need to add that line in your code in form ctor: this.gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.Any; Stefan


AD Administrator Syncfusion Team April 26, 2004 11:14 AM UTC

You could either call grdQuote.GetTable("MyChildTableName").CurrentRecord; - or - Element el = grdQuote.Table.CurrentElement; NestedTable nt = el as NestedTable; if (nt != null) el = nt.ChildTable.ParentTable.CurrentElement; If you have even more levels, you could do that in a loop: Element el = grdQuote.Table.CurrentElement; NestedTable nt = el as NestedTable; while (nt != null) { el = nt.ChildTable.ParentTable.CurrentElement; nt = el as NestedTable; } Stefan >Hi againg. >grdQuote.Table.CurrentRecord works correctly if selected row is a row of top level table.. But my dataset contains two tables. And if I select a row in the nested table grdQuote.Table.CurrentRecord returns null. >


SI Silenter April 27, 2004 04:15 AM UTC

Hi Stefan. After changing data in the selected row grid.Table.CurrentElement returns null. You can reproduce it: 1. Fill the dataset. 2. Select First row. 3. Get grid.Table.CurrentElement. Ok. 4. Change data in the first row 5. Get grid.Table.CurrentElement == null. Why? You can test it by this code: Element el = grid.Table.CurrentElement; if( el is NestedTable ) el = ((NestedTable)el).ChildTable.ParentTable.CurrentElement; Object data = el.GetData(); // change data in the first row dataset11.Author[0].Name = "Author " + DateTime.Now.ToString(); el = grid.Table.CurrentElement; if( el == null ) { MessageBox.Show("There is no CurrentElement"); return; } or find example at SyncGridSelectedRowTest_9220.zip Regards, Slava.


AD Administrator Syncfusion Team April 27, 2004 04:55 PM UTC

In the ListChanged event handler the engine checks if the current record is being changed from the outside and if that is the case it deactivates the current record. Only if changes are made by the user within the grid then the current record stays intact. I agree this is not good behavior and we should review this. For now, you can workaround this by calling // change data in the first row dataset11.Author[0].Name = "Author " + DateTime.Now.ToString(); el.ParentTable.CurrentElement = el; If a different reocrd was changed the line will have no effect. If the same record was changed it will reactivate the current record to its old position. Stefan

Loader.
Live Chat Icon For mobile
Up arrow icon