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.

AddNewRecord addition

Thread ID:

Created:

Updated:

Platform:

Replies:

49181 Sep 12,2006 04:49 PM Sep 19,2006 07:13 PM Windows Forms 4
loading
Tags: Grouping
Paulo Cristini
Asked On September 12, 2006 04:49 PM

I have a couple questions pertaining to adding new records to a grid:

1) When adding a new record I want the focus of the current record to stay on the AddNewRecord row after the new record has been added to the datasource.

2) I am fetching some additional data into the data row from the database when the user enters values into some initial columns. After fetching the data and updating the particular row with the values from the database, the rows themselves are not updated within the grid until after the row is added to the datasource. Is there anyway to force the grid to update the values within the addnewrecord row with the data fetched from the database?

Administrator [Syncfusion]
Replied On September 13, 2006 03:26 AM

Hi Paul,

Issue 1:

You can call the SetCurrent method to set the focus of the record in a GridTable. Below is a code snippet.

//Set the Focus to the AddNewRecord.
int Addnewindex = this.gridGroupingControl1.Table.UnsortedRecords.Count;
Syncfusion.Grouping.Record rec = this.gridGroupingControl1.Table.UnsortedRecords[Addnewindex-1];
rec.SetCurrent("YourColumnName");

Issue 2:

Try this:

this.groupingGrid.BeginUpdate()
this.groupingGrid.Table.TableDirty = true

-- make your changes

this.groupingGrid.EndUpdate(false)
this.groupingGrid.Refresh();
// or this.grid.Reinitialize();

TableDirty = true tells the grid that the table is dirty and subsequent ListChanged events can be ignored.

Otherwise each change you make to the DataTable will result in realtime updating of counters and summaries of the table. (Each time a Log2(n) operation which is good if you do a few updates but not if you know you are looping through the whole table anyway ...).

So, with TableDirty = true, the operation count will be n. Without TableDirty = true it will be n*log2(n).

Here is a sample.
http://www.syncfusion.com/Support/user/uploads/GGCUpdate_41f8aa57.zip

Regards,
Haneef

Paulo Cristini
Replied On September 13, 2006 11:53 AM

Haneef,

I think there may have been some miscommunication in what I was looking for. I''ll try and clarify both situations

1) I''d like the focus to stay on the AddNewRecord cell type, ie. The record with the *, or in the case of your example the first row in the grid. I''d also like to do this within the events of the grid so that when I hit enter on the new record (to add it to the rest of the grid) the focus will be placed on the new record. Currently I''m attempting to do it within the CurrentRecordContextChange event when the Action is EndEditComplete, but I get some interesting behavior when trying to set the current record to the AddNewRecord row. Here is what I''m doing currently. Its seems as though this resets the AddNewRecord row

//lastAddNewRecord is a boolean stating that the record that is receiving the context change was the add new record row
if ((e.Action == CurrentRecordAction.EndEditCalled) && (e.Record.Kind == DisplayElementKind.AddNewRecord))
{
this.lastAddNewRecord = true;
}
else if(this.lastAddNewRecord && e.Action == CurrentRecordAction.EndEditComplete)
{
this.ggc.Table.CurrentRecord = this.ggc.Table.AddNewRecord;
this.lastAddNewRecord = false;
}

2) Setting the TableDirty flag to true is causing the AddNewRecord row to be added to the rest of the grid before the user has navigated out of the row. Maybe an example of the behaviour I''m looking for will give you a better idea.
Grid layout:
----------------------------------
| Employee | Wage | Location |
----------------------------------
*| | | |
----------------------------------

Step 1) User Enters employee number
----------------------------------
| Employee | Wage | Location |
----------------------------------
*| 345 | | |
----------------------------------

2) User tabs out of employee number field
3) In RecordValueChanged event validate the employee number and retrieve the location from the database. (see **note below for question about the events)
4) Display the location in the appropriate field (Issue 1)
----------------------------------
| Employee | Wage | Location |
----------------------------------
*| 345 | | Store 3 |
----------------------------------

5) User enters salaray
----------------------------------
| Employee | Wage | Location |
----------------------------------
*| 345 | 8.50 | Store 3 |
----------------------------------

6) User presses enter and the record is added to the rest of the grid. And focus is returned to the AddNewRecord row (Issue 2)

--------------------------------------
| Employee | Wage | Location |
--------------------------------------
*|/*FOCUS HERE*/| | |
--------------------------------------
| 345 | 8.50 | Store 3 |
--------------------------------------


**Note: I haven''t been able to figure the best event to handle this situation (whether I do it in RecordValueChanged, or Validating, or Validated). The reasoning behind this was that in our actual application the user will be entering values for multiple columns to search based on (step 3 will use multiple values to retrieve the appropriate information). If I try to do this in the Validating event, the record hasn''t been populated with the newly entered value yet thus making the retrieval more difficult.

Thanks,
Paulo

Administrator [Syncfusion]
Replied On September 18, 2006 06:53 AM

Hi Paulo,

I am sorry for the delay in getting back to you

Issue 1:

You can handle the TableControlCurrentCellKeyDown event to navigate the cell focus in a AddnewRecord when the Enter keys is pressed. Below is a code snippet.

private void gridTableControlCurrentCellKeyDown(object sender, GridTableControlKeyEventArgs e)
{
if( e.Inner.KeyData == Keys.Enter && isAddNewRecord)
{
isAddNewRecord = false;
e.TableControl.Table.AddNewRecord.SetCurrent();
e.Inner.Handled = false;
}
}

Issue 2:

Please refer to the below KB article for more details on Validation of a cell.
http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=49232

Please let me know if you need any further assistance.

Best Regards,
Haneef

Paulo Cristini
Replied On September 19, 2006 07:13 PM

Issue 1:

What''s the best way to set the boolean saying whether the last cell was an addnewrecord? I''ve tried setting it in the CurrentRecordContextChange event when the action is EndEditComplete

if (e.Action == CurrentRecordAction.EnterRecordComplete)
{
this.focusAddNew = (e.Record.Kind == DisplayElementKind.AddNewRecord);
}

The problem with this is that the TableControlCurrentCellKeyDown event is processed AFTER the record has been finalized, and added to the dataset (thus changing the state of the record from addnewrecord to just record) which in turn sets the boolean stating whether the last record was an addnewrecord to false (because the CurrentRecordContextChange event is fired when the the record is added to the dataset)

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.

;