On 28 Feb 2006 06:19:52 -0800, "su*************@googlemail.com"
<su*************@googlemail.com> wrote:
Following on from my original message,
How would i go about retrieving a value from the parent form in the
child?
e.g.
A user right clicks on a TreeView node and selects "Rename..."
A dialog form comes up, but how do I populate a textbox with the
SelectedNode on the parent form?
I've tried this:
StockCategories mainForm = new StockCategories();
stockCategoryName.Text =
mainForm.treeView.SelectedNode.ToString();
But mainForm.treeView.SelectedNode.ToString() is null. I guess I'm
going totally wrong with trying to create "mainForm"?
I also tried calling the child form like this: editStockCategory f =
new editStockCategory(treeView.SelectedNode.Text);
and then when declaring the child form I put this: public
editStockCategory(string nodeText)
But I'm not sure how to make nodeText available in the child form Load
event.
Arghhh.
Susan
The SelectedNode.ToString() doesn't return to value for the Text
attribute of the node. Use SelectedNode.Text instead.
But first, before doing that, make sure that a node is selected to
prevent errors.
if (MyTreeview.SelectedNode != null)
{
... do my stuff
Setting Text is also not correct. The Text attribute for the form is
just the Dialog caption, not the actual textbox. You could try to set
to modifiers of the textbox to internal or public. That way you could
access the textbox using
mainForm.TextBox1.Text
But I would suggest to create a new property in the code of the form
which uses the textbox like this:
internal string NodeValue
{
get { return Textbox1.Text; }
set { Textbox1.Text = value; }
}
that way you could use
mainForm.NodeValue = SelectedNode.Text
in total: you create the form like this (based upon the "fact" that
your childform performs a database-update all by itself):
StockCategories mainForm = new StockCategories();
mainForm.NodeValue = MyTreeview.SelectedNode.Text
if (mainForm.ShowDialog() == DialogResult.Ok)
{
MyTreeview.SelectedNode.Text = mainForm.NodeValue;
}
Besides that, one suggestion, do not use "mainForm" as variable name,
since it is not your mainForm :-)
greetz,
Leon