I''m trying to use a DataTable with a single field to implement a queue. This table is the datasource for a GridDataBoundGrid. I''d like the user to be able to add to the end of the list while allowing the program to consume (delete) elements at the beginning of the list.
The problem happens when the user is adding an element to the end of the list in the GridDataBoundGrid at the time the program deletes an element from the front of the datatable. The list appears to update, and you can continue editing the field, but when you tab off it I get a message like "There is no row at position 2".
Can you suggest a way to keep things in sync?
Thanks
AD
Administrator
Syncfusion Team
February 20, 2006 07:04 AM UTC
Hi Ken,
I am able to see the issue only when I handle the Binder.EditModeChanged event and edit the last row but, not when adding a new row. In this case we are deleting the first row when the last row is being edited and thus causing the IndexOutOfRangeException. The gridDataBoundGrid1.RowEditing event can be used to achieve the same without the mentioned issue. Attached is a sample, see if that helps.
private void gridDataBoundGrid1_RowEditing(object sender, GridRowEventArgs e)
{
if(this.gridDataBoundGrid1.EnableAddNew && e.RowIndex == this.gridDataBoundGrid1.Model.RowCount)
{
DataTable dt = this.gridDataBoundGrid1.DataSource as DataTable;
dt.Rows[0].Delete();
}
}
Regards,
Calvin.
40992.zip
AD
Administrator
Syncfusion Team
February 20, 2006 03:31 PM UTC
Thanks for the help Calvin.
My issue is a bit more complicated because the item at the head of the list (table) is being removed by another part of the program at an indeterminate time. In other words, I can''t use an event related to editing to delete the row.
Is there any way I could respond to an event from the Table itself, like RowDeleting or RowDeleted to "fix" things if editing is happening?
Thanks
Ken
KL
Ken Law
February 20, 2006 11:36 PM UTC
Any ideas on this problem?
An automated system measuring crankshafts is consuming serial numbers from a list. An operator is inputting serial numbers at the end of the list using a grid control. It would be nice if the operator could also move to a cell to correct an entry.
The problem is the list must be updated in two cases - if the automation removes a serial number, or if the operator adds or edits a serial number not yet consumed.
I''ve thought about maintaining two lists: one being edited, and one used by the automation. The problem then becomes how do I keep them in sync and updated.
I could probably prevent the automation side from updating the editable list if I could determine whether the list was being edited. Then, I could syncronize the editable list with the automation list after each edit, and update it when the automation consumed a number while the list was not being edited.
AD
Administrator
Syncfusion Team
February 21, 2006 11:19 AM UTC
Hi Ken,
Please refer the attached sample and see if that helps.
Regards,
Calvin.
41029.zip
KL
Ken Law
February 21, 2006 05:01 PM UTC
Thanks Calvin
Looks promising - I''ll work with it and let you know if it works out.
Ken
KL
Ken Law
February 25, 2006 03:39 PM UTC
Calvin,
Thanks again - your sample has helped me very much. You guys have great support!
I do have another question, however. I have to allow several items to be used from the queue even though the grid does not update because it is in edit mode. When leaving edit mode, several rows may be deleted at the same time to update the grid.
I have all that working - my problem now is that I need to be able to programatically force the current cell to be the "new" one at the end of the list. I don''t want it to go into edit mode until the user started typing data into it, but I need to programatically move the focus to that cell after the grid updates so all the user does have to do is start typing. Any suggestions?
KL
Ken Law
February 28, 2006 02:03 PM UTC
Calvin,
I could really use help with this. I have a release in a few days and need to get this functionality working.
Thanks
AD
Administrator
Syncfusion Team
March 1, 2006 10:47 AM UTC
Hi Ken,
I apologize for the delay in replying. The current cell can be set to the last (new row) cell by calling the this.gridDataBoundGrid1.CurrentCell.MoveTo(this.gridDataBoundGrid1.Model.RowCount,this.gridDataBoundGrid1.Model.ColCount,GridSetCurrentCellOptions.ScrollInView); Try the below snipped code in the previous sample.
private void t_Tick(object sender, EventArgs e)
{
if(!fl)
{
Timer t = sender as Timer;
t.Stop();
t.Dispose();
i=-1;
fl = true;
}
i++;
if(i==20)
{
if(!InAddNewOREdit && this.myTable.Rows.Count >2)
{
this.myTable.Rows[0].Delete(); //Deleting First Row from DataTable
this.gridDataBoundGrid1.CurrentCell.MoveTo(this.gridDataBoundGrid1.Model.RowCount,this.gridDataBoundGrid1.Model.ColCount,GridSetCurrentCellOptions.ScrollInView);
i=0;
}
else
--i;
}
}
Best Regards,
Calvin.
KL
Ken Law
March 3, 2006 01:41 PM UTC
Thanks Calvin. That works well.
Great support!