Q: SendKeys and MdiChildren

  • Thread starter Thread starter Soul
  • Start date Start date
S

Soul

Hi,

I have multiple Mdi child forms within a parent form. All Mdi child forms
will have one DataGrid on it, the DataGrid is bind to a DataView and the
DataView is again bind to a DataTable. In addition, there is a save button
on the parent form.

My problem is if a user finish input data into the last cell of the DataGrid
of an active child form but never press the control+enter key or navigate to
other cell. The current row will still in edit mode (a pen icon infornt of
the first column of current row).

Then if the user press on the save button on the parent form, the last input
data will not be saved. I have tried SendKeys, but it doesn't work!!

When the save button being clicked, it will loop through all Mdi child forms
and call the following function in all Mdi child forms to get the updated
DataTable:

public DataTable UpdatedTable
{
get
{
SendKeys.Send("^{ENTER}");
return this.dataTable.GetChanges();
}
}

I understand that the SendKey doesn't have to be in all Mdi child forms, I
am just testing it out. Can anyone help me on this issue?

Thank you.
 
Soul,

I think that what you want to do is get the BindingManagerBase for the
form (which is keyed on the DataView that the grid is bound to). When you
have that, you can call the EndCurrentEdit method and it should commit
whatever you were editing. You can do this before you save the data back to
the grid.

Hope this helps.
 
Hi,

I tried, but it doesn't work. I think it is because I don't really
understand about the BindingManagerBase. I tried to follow the example from
MSDN and modified my code as follow:

// private variebles declared here
....
....

public myForm(DataTable aTable)
{
InitializeComponent();

this.myDT = aTable;
this.tableName = this.myDataTable.TableName.ToString();
this.myDV = new DataView(this.myDT);
this.myDG.DataSource = this.myDV;

/* I think I did something wrong here. */
this.bingingManagerBase = (CurrencyManager) BindingContext[this.myDV];

this.myDV.AllowNew = false;
this.myDV.AllowDelete = true;
this.dataGridTableStyle.MappingName = tableName;
this.myDT.ColumnChanging += new
DataColumnChangeEventHandler(this.dataTable_ValueChanging);
}

public DataTable UpdatedTable
{
get
{
this.bingingManagerBase.EndCurrentEdit();

MessageBox.Show(this.dataTable.Rows[this.dataGrid.CurrentCell.RowNumber]["ta
skMarks"].ToString());
return this.dataTable.GetChanges();
}
}

Once the user click on the save button on the parent form, the UpdatedTable
in the child form will be called. But I still see the current editing row of
the DataGrid in the active child form still in editing mode.

Please show me where did I miss out?

Thank you.

--
Soul


message | Soul,
|
| I think that what you want to do is get the BindingManagerBase for the
| form (which is keyed on the DataView that the grid is bound to). When you
| have that, you can call the EndCurrentEdit method and it should commit
| whatever you were editing. You can do this before you save the data back
to
| the grid.
|
| Hope this helps.
|
|
| --
| - Nicholas Paldino [.NET/C# MVP]
| - (e-mail address removed)
|
| |
| > [Snipped]
 
Ah Ha... I found the solution!

....
this.dataView = new DataView(this.dataTable);
this.dataGrid.DataSource = this.dataView;
this.currencyManager = (CurrencyManager)
this.BindingContext[this.dataTable];

public void CompleteEdit()
{
this.dataGrid.EndEdit(this.dataGridTextBoxColumnTaskMarks,
this.dataGrid.CurrentCell.RowNumber, false);
this.currencyManager.Position = this.dataGrid.CurrentCell.RowNumber;
this.currencyManager.EndCurrentEdit();
}

But I don't understand why calling the CurrencyManager.EndCurrentEdit() is a
must after calling the DataGrid.EndEdit()!?!?

--
Soul


| Hi,
|
| I tried, but it doesn't work. I think it is because I don't really
| understand about the BindingManagerBase. I tried to follow the example
from
| MSDN and modified my code as follow:
|
| // private variebles declared here
| ...
| ...
|
| public myForm(DataTable aTable)
| {
| InitializeComponent();
|
| this.myDT = aTable;
| this.tableName = this.myDataTable.TableName.ToString();
| this.myDV = new DataView(this.myDT);
| this.myDG.DataSource = this.myDV;
|
| /* I think I did something wrong here. */
| this.bingingManagerBase = (CurrencyManager) BindingContext[this.myDV];
|
| this.myDV.AllowNew = false;
| this.myDV.AllowDelete = true;
| this.dataGridTableStyle.MappingName = tableName;
| this.myDT.ColumnChanging += new
| DataColumnChangeEventHandler(this.dataTable_ValueChanging);
| }
|
| public DataTable UpdatedTable
| {
| get
| {
| this.bingingManagerBase.EndCurrentEdit();
|
|
MessageBox.Show(this.dataTable.Rows[this.dataGrid.CurrentCell.RowNumber]["ta
| skMarks"].ToString());
| return this.dataTable.GetChanges();
| }
| }
|
| Once the user click on the save button on the parent form, the
UpdatedTable
| in the child form will be called. But I still see the current editing row
of
| the DataGrid in the active child form still in editing mode.
|
| Please show me where did I miss out?
|
| Thank you.
|
| --
| Soul
|
|
in
| message | | Soul,
| |
| | I think that what you want to do is get the BindingManagerBase for
the
| | form (which is keyed on the DataView that the grid is bound to). When
you
| | have that, you can call the EndCurrentEdit method and it should commit
| | whatever you were editing. You can do this before you save the data
back
| to
| | the grid.
| |
| | Hope this helps.
| |
| |
| | --
| | - Nicholas Paldino [.NET/C# MVP]
| | - (e-mail address removed)
| |
| | | |
| | > [Snipped]
|
 
Back
Top