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
close icon

Sorting while adding a new record

Hi I am facing a problem in GGC while adding a new record. While addding a new record if the grid is in sorting order--After EndEditCalled the entered record will also be sorted,So i want to set facus on the same record as user no need to search it.He can get the location for the record he has just entered.Or how can i get the RowIndex of that record after sorting applied. Thanks & Reguards Vihar..

9 Replies

AD Administrator Syncfusion Team June 9, 2006 12:09 PM UTC

Hi Vihar, By default, when a record is added through AddNewRow and when the enter key is pressed the current record will be the newly added row and the TableControl.CurrentCell.ScrollInView()can be called in the TableControl.CurrentCellMoved event handler if the current row is not in the visible bounds. Sample attached. If the row is added directly to the table then please refer to the below forum thread that deals with the same issue. http://www.syncfusion.com/Support/forums/message.aspx?MessageID=38558 Let us know if you need any further assistance. Regards, Calvin.

SampleSorting..zip


VI Vihar June 12, 2006 08:30 AM UTC

hi Calvin,i am geeting newly added record in the view. But actualy i want to change the backcolor only for the row in which the new record is there after sorting has been applied. So user can have ease to get the idea for that record. As in Syncfusion that record row has the tringle in the first coloum. I want to chang the back color for that row only , Is there any idea for this probelm? I tried SetSelected(),But its not workin, i tried this thing,,But its not working. private void _gridGrouping_CurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e) { this._gridGrouping.TableControl.Table.SelectedRecords.Clear(); if((e.Action == CurrentRecordAction.EndEditCalled) && (e.Record.Kind == DisplayElementKind.AddNewRecord)) { Record _rec = e.Record as Record; this._gridGrouping.TableControl.Table.SelectedRecords.Add(_rec); _rec.SetSelected(true); _rec.SetCurrent(); } } >Hi Vihar, > >By default, when a record is added through AddNewRow and when the enter key is pressed the current record will be the newly added row and the TableControl.CurrentCell.ScrollInView()can be called in the TableControl.CurrentCellMoved event handler if the current row is not in the visible bounds. Sample attached. > >If the row is added directly to the table then please refer to the below forum thread that deals with the same issue. > >http://www.syncfusion.com/Support/forums/message.aspx?MessageID=38558 > >Let us know if you need any further assistance. > >Regards, >Calvin.

SampleSorting..zip


AD Administrator Syncfusion Team June 12, 2006 09:29 AM UTC

Hi Vihar, When the current record context changes by the EndEditCalled, the current row will be still the AddNewRow, and _rec.SetSelected(true) will try to select the AddNewRow which is not feasible. To select the newly added record row call the _rec.SetSelected() when the current record context changes by the EndEditComplete. Below is a code snippet. bool lastAddNewRow = false; private void _gridGrouping_CurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e) { this._gridGrouping.TableControl.Table.SelectedRecords.Clear(); Record _rec = e.Record as Record; if((e.Action == CurrentRecordAction.EndEditCalled) && (e.Record.Kind == DisplayElementKind.AddNewRecord)) { _rec.SetCurrent(); endAddNew = true; } else if(lastAddNewRow && e.Action == CurrentRecordAction.EndEditComplete) { _rec.SetSelected(true); lastAddNewRow = false; } } Regards, Calvin.


VI Vihar June 12, 2006 07:48 PM UTC

Hi Calvin Thanks for reply, In your answer what do u mean by "endAddNew = true;" where have you declare this variable?And if its "lastAddNewRow".and bymistake u write that, then also its not working the record is not getting selected.. If any how i can get the index for that record---that is after applying sorting on which index that record is then i can try this.. _gridGrouping.Table.Records[index].SetSelected(true); _gridGrouping.Table.Records[index].SetCurrent(); what do u suggest? >Hi Vihar, > >When the current record context changes by the EndEditCalled, the current row will be still the AddNewRow, and _rec.SetSelected(true) will try to select the AddNewRow which is not feasible. To select the newly added record row call the _rec.SetSelected() when the current record context changes by the EndEditComplete. Below is a code snippet. > > bool lastAddNewRow = false; > private void _gridGrouping_CurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e) > { > this._gridGrouping.TableControl.Table.SelectedRecords.Clear(); > Record _rec = e.Record as Record; > if((e.Action == CurrentRecordAction.EndEditCalled) && (e.Record.Kind == DisplayElementKind.AddNewRecord)) > { > _rec.SetCurrent(); > endAddNew = true; > } > else > if(lastAddNewRow && e.Action == CurrentRecordAction.EndEditComplete) > { > _rec.SetSelected(true); > lastAddNewRow = false; > } > > > } > >Regards, >Calvin.


AD Administrator Syncfusion Team June 13, 2006 03:37 AM UTC

Hi Vihar, Sorry, its lastAddNewRow and here is a sample with the above mentioned code snippet that works as expected. Regards, Calvin.

SampleSorting0.zip


VI Vihar June 14, 2006 07:12 AM UTC

Hi Calvin, Thanks for the given solution. This is actually what I want. But I don’t know why it’s not working here. Even I have did the same thing in other grid in the same solution. And there it is working fine. There I wrote this code— _gridGrouping.Table.Records [Index].SetSelected (true); _gridGrouping.Table.Records [Index].SetCurrent(); The only different between those two gird is this, The grid in which I had implemented this thing is a simple GridGroupingControl without any parent –child relationship, and the grid in which I want to implement the same is with parent child relationship and can be expandable. Is there any constrain for this code that weather it will work for simple grid and not for the grid which has expandable feather or has any relationship. Because in your code its working fine but the same code is not working in my solution. Only difference is one grid is simple and other grid is with relationship. >Hi Vihar, > >Sorry, its lastAddNewRow and here is a sample with the above mentioned code snippet that works as expected. > >Regards, >Calvin.

SampleSorting0.zip


AD Administrator Syncfusion Team June 14, 2006 10:46 AM UTC

Hi Vihar, When having hierarchical grid, the CurrentRecordContextChange event must be handled for both the parent and the child tables. Below is a code snippet. //Add Event handler for parent table this.gridGroupingControl1.Table.CurrentRecordContextChange += new CurrentRecordContextChangeEventHandler(Table_CurrentRecordContextChange); //Add the event handler for child table this.gridGroupingControl1.GetTable(childTable.TableName).CurrentRecordContextChange += new CurrentRecordContextChangeEventHandler(Table_CurrentRecordContextChange); private void Table_CurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e) { GridTable table = sender as GridTable; table.SelectedRecords.Clear(); Record _rec = e.Record as Record; if((e.Action == CurrentRecordAction.EndEditCalled) && (e.Record.Kind == DisplayElementKind.AddNewRecord)) { _rec.SetCurrent(); lastAddNewRow = true; } else if(lastAddNewRow && e.Action == CurrentRecordAction.EndEditComplete) { _rec.SetSelected(true); lastAddNewRow = false; } } Regards, Calvin.


VI Vihar June 14, 2006 12:58 PM UTC

Hi Calvin still need a help. According to your trips i tries the same as u suggestd but then also i dont knoe why its not working, In which case it should not working accordingly.? i am sending u a code sampel what i did. public void RagisterEvents(GridGroupingControl grid) { if(this._gridGrouping != grid) { if(this._gridGrouping != null) this._gridGrouping = grid; this._gridGrouping.CurrentRecordContextChange+=new ChangeEventHandler(Table_CurrentRecordContextChange); int iRelationsCount = this._gridGrouping.TableDescriptor.Relations.Count; for(int i=0; i < iRelationsCount;i++) { GridRelationDescriptor gRelationDesc = this._gridGrouping.TableDescriptor.Relations[i]; if(gRelationDesc.RelationKind == RelationKind.RelatedMasterDetails) { try { GridTableModel tableModel = this._gridGrouping.GetTableModel(gRelationDesc.Name); if(tableModel != null) { tableModel.CurrentRecordContextChange+=new CurrentRecordContextChangeEventHandler (Table_CurrentRecordContextChange); } } catch{} } } } } bool lastAddNewRow = false; private void Table_CurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e) { GridGroupingControl ggC = sender as GridGroupingControl; GridTable table = ggC.Table as GridTable; table.SelectedRecords.Clear(); Record _rec = e.Record as Record; if((e.Action == CurrentRecordAction.EndEditCalled) && (e.Record.Kind == DisplayElementKind.AddNewRecord)) { _rec.SetCurrent(); lastAddNewRow = true; } else if(lastAddNewRow && e.Action == CurrentRecordAction.EndEditComplete) { _rec.SetSelected(true); lastAddNewRow = false; } } >Hi Vihar, > >When having hierarchical grid, the CurrentRecordContextChange event must be handled for both the parent and the child tables. Below is a code snippet. > >//Add Event handler for parent table this.gridGroupingControl1.Table.CurrentRecordContextChange += new CurrentRecordContextChangeEventHandler(Table_CurrentRecordContextChange); > >//Add the event handler for child table this.gridGroupingControl1.GetTable(childTable.TableName).CurrentRecordContextChange += new CurrentRecordContextChangeEventHandler(Table_CurrentRecordContextChange); > > > >private void Table_CurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e) > { > GridTable table = sender as GridTable; > table.SelectedRecords.Clear(); > Record _rec = e.Record as Record; > if((e.Action == CurrentRecordAction.EndEditCalled) && (e.Record.Kind == DisplayElementKind.AddNewRecord)) > { > _rec.SetCurrent(); > lastAddNewRow = true; > } > else > if(lastAddNewRow && e.Action == CurrentRecordAction.EndEditComplete) > { > _rec.SetSelected(true); > lastAddNewRow = false; > } > > > } > > > > >Regards, >Calvin.


AD Administrator Syncfusion Team June 15, 2006 04:12 AM UTC

Hi Vihar, Add the event handler to Table. CurrentRecordContextChange and in the event handler, the respective table can be retrieved from the sender. Below is your modified code. In your code, when the event is fired from the tableModel.CurrentRecordContextChange the sender will be the GridTableModel and not the GridGroupingControl. And the groupingGrid.Table always returns the top level table. public void RagisterEvents(GridGroupingControl grid) { if(this._gridGrouping != grid) { if(this._gridGrouping != null) this._gridGrouping = grid; this._gridGrouping.Table.CurrentRecordContextChange+=new ChangeEventHandler(Table_CurrentRecordContextChange); int iRelationsCount = this._gridGrouping.TableDescriptor.Relations.Count; for(int i=0; i < iRelationsCount;i++) { GridRelationDescriptor gRelationDesc = this._gridGrouping.TableDescriptor.Relations[i]; if(gRelationDesc.RelationKind == RelationKind.RelatedMasterDetails) { try { GridTable table = this._gridGrouping.GetTable(gRelationDesc.Name); if(table != null) { table.CurrentRecordContextChange+=new CurrentRecordContextChangeEventHandler (Table_CurrentRecordContextChange); } } catch{} } } } } bool lastAddNewRow = false; private void Table_CurrentRecordContextChange(object sender, CurrentRecordContextChangeEventArgs e) { GridTable table = sender as GridTable; table.SelectedRecords.Clear(); Record _rec = e.Record as Record; if((e.Action == CurrentRecordAction.EndEditCalled) && (e.Record.Kind == DisplayElementKind.AddNewRecord)) { _rec.SetCurrent(); lastAddNewRow = true; } else if(lastAddNewRow && e.Action == CurrentRecordAction.EndEditComplete) { _rec.SetSelected(true); lastAddNewRow = false; } } Regards, Calvin.

Loader.
Live Chat Icon For mobile
Up arrow icon