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.

GridGroupingControl(2.0.5.0) Selected Row

Thread ID:

Created:

Updated:

Platform:

Replies:

13280 Apr 24,2004 03:20 AM Apr 27,2004 12:55 PM Windows Forms 8
loading
Tags: Grouping
Silenter
Asked On April 24, 2004 03:20 AM

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

Administrator [Syncfusion]
Replied On April 24, 2004 07:03 AM

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

Silenter
Replied On April 26, 2004 04:28 AM

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?

Silenter
Replied On April 26, 2004 05:51 AM

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.

Silenter
Replied On April 26, 2004 06:19 AM

>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

Administrator [Syncfusion]
Replied On April 26, 2004 07:10 AM

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

Administrator [Syncfusion]
Replied On April 26, 2004 07:14 AM

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. >

Silenter
Replied On April 27, 2004 12:15 AM

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.

Administrator [Syncfusion]
Replied On April 27, 2004 12:55 PM

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

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.

;