By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,132 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,132 IT Pros & Developers. It's quick & easy.

Q: SendKeys and MdiChildren

P: n/a
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

Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Soul" <no@spam.com> wrote in message
news:eY***************@tk2msftngp13.phx.gbl...
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

Nov 15 '05 #2

P: n/a
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_ValueC hanging);
}

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
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Of**************@TK2MSFTNGP10.phx.gbl...
| 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]
| - mv*@spam.guard.caspershouse.com
|
| "Soul" <no@spam.com> wrote in message
| news:eY***************@tk2msftngp13.phx.gbl...
|
| > [Snipped]

Nov 15 '05 #3

P: n/a
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.dataGridTextBoxColumnTa skMarks,
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
"Soul" <no@spam.com> wrote in message
news:e8**************@TK2MSFTNGP11.phx.gbl...
| 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_ValueC hanging);
| }
|
| 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
|
|
| "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
| message news:Of**************@TK2MSFTNGP10.phx.gbl...
| | 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]
| | - mv*@spam.guard.caspershouse.com
| |
| | "Soul" <no@spam.com> wrote in message
| | news:eY***************@tk2msftngp13.phx.gbl...
| |
| | > [Snipped]
|

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.