473,803 Members | 3,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# beginners question

Hi

I'm sure there is a very simple answer to this but it's got me stuck
for hours!

How do you change the properties of parent forms? e.g. if you have a
dialog box that has a textbox on it, when the user clicks an OK Button,
and the value is saved to the database, how do you then update the
treeview on the main parent form?

I'm creating a new instance of the form within the child, which gives
me access to the Nodes but it doesn't allow me to change any thing?

To make things simpler, I tried to change the .Text property of the
parent form within the child form but I can't even seem to do that.

I'm sure I'm missing something really simple!

Thanks for your time
Susan

Feb 28 '06 #1
9 1302
Hi,

Well I wouldn't really do it that way.

Your parent form needs to check the result of the child dialog and then act
accordingly. As a general rule you wouldn't have a child telling the parent
what to do - well not in my family :-)

So,

parent creates child dialog
child dialog does stuff
parent checks child state and then thinks "OK, I'll change this text, or
light up this button etc."

Hope this general comment helps,

Cheers,

Adam.
<su************ *@googlemail.co m> wrote in message
news:11******** **************@ i40g2000cwc.goo glegroups.com.. .
Hi

I'm sure there is a very simple answer to this but it's got me stuck
for hours!

How do you change the properties of parent forms? e.g. if you have a
dialog box that has a textbox on it, when the user clicks an OK Button,
and the value is saved to the database, how do you then update the
treeview on the main parent form?

I'm creating a new instance of the form within the child, which gives
me access to the Nodes but it doesn't allow me to change any thing?

To make things simpler, I tried to change the .Text property of the
parent form within the child form but I can't even seem to do that.

I'm sure I'm missing something really simple!

Thanks for your time
Susan

Feb 28 '06 #2
On 28 Feb 2006 04:05:09 -0800, su************* @googlemail.com wrote:
Hi

I'm sure there is a very simple answer to this but it's got me stuck
for hours!

How do you change the properties of parent forms? e.g. if you have a
dialog box that has a textbox on it, when the user clicks an OK Button,
and the value is saved to the database, how do you then update the
treeview on the main parent form?

I'm creating a new instance of the form within the child, which gives
me access to the Nodes but it doesn't allow me to change any thing?

To make things simpler, I tried to change the .Text property of the
parent form within the child form but I can't even seem to do that.

I'm sure I'm missing something really simple!

Thanks for your time
Susan


Susan,

there are multiple ways of doing this, but first things first. When
clicking the OK button you should set the dialogresult of the
dialogbox to DialogResult.Ok (and initially the dialogresult to
cancel)
When you create the form like this:

if (new MyDialog.ShowDi alog() == DialogResult.Ok )
{
// Update treeview
}

You know when the user clicked OK.

You could then reload the entire treeview or (to save time and
resources) ask for the textbox value and update the selectednode.te xt

greetz, Leon.
Feb 28 '06 #3

<su************ *@googlemail.co m> wrote in message
news:11******** **************@ i40g2000cwc.goo glegroups.com.. .
Hi

I'm sure there is a very simple answer to this but it's got me stuck
for hours!

How do you change the properties of parent forms? e.g. if you have a
dialog box that has a textbox on it, when the user clicks an OK Button,
and the value is saved to the database, how do you then update the
treeview on the main parent form?


If the dialog is modal then you just update the main form when it returns.

If it is not modal then having an event on the dialog is the cleanest way
forward.

If you think of the dialog as just another sort of control but with rather
more data than a simple control then you can see how to go about things.

Often you'll find that you want to use a something like CancelEventArgs to
allow the main form to veto the action and prevent the dalog from closing.
Feb 28 '06 #4
Adan, Leon

Thanks for your quick replies,

Everything suddenly makes so much more sense!

I've changed things around in the way you suggest and it's working
great now. It's such a great feeling to get around this hurdle! =)

Susan

Leon Friesema wrote:
On 28 Feb 2006 04:05:09 -0800, su************* @googlemail.com wrote:
Hi

I'm sure there is a very simple answer to this but it's got me stuck
for hours!

How do you change the properties of parent forms? e.g. if you have a
dialog box that has a textbox on it, when the user clicks an OK Button,
and the value is saved to the database, how do you then update the
treeview on the main parent form?

I'm creating a new instance of the form within the child, which gives
me access to the Nodes but it doesn't allow me to change any thing?

To make things simpler, I tried to change the .Text property of the
parent form within the child form but I can't even seem to do that.

I'm sure I'm missing something really simple!

Thanks for your time
Susan


Susan,

there are multiple ways of doing this, but first things first. When
clicking the OK button you should set the dialogresult of the
dialogbox to DialogResult.Ok (and initially the dialogresult to
cancel)
When you create the form like this:

if (new MyDialog.ShowDi alog() == DialogResult.Ok )
{
// Update treeview
}

You know when the user clicked OK.

You could then reload the entire treeview or (to save time and
resources) ask for the textbox value and update the selectednode.te xt

greetz, Leon.


Feb 28 '06 #5
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 ();
stockCategoryNa me.Text =
mainForm.treeVi ew.SelectedNode .ToString();

But mainForm.treeVi ew.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: editStockCatego ry f =
new editStockCatego ry(treeView.Sel ectedNode.Text) ;
and then when declaring the child form I put this: public
editStockCatego ry(string nodeText)

But I'm not sure how to make nodeText available in the child form Load
event.

Arghhh.

Susan

Feb 28 '06 #6
On 28 Feb 2006 06:19:52 -0800, "su************ *@googlemail.co m"
<su************ *@googlemail.co m> 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 ();
stockCategoryNa me.Text =
mainForm.treeV iew.SelectedNod e.ToString();

But mainForm.treeVi ew.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: editStockCatego ry f =
new editStockCatego ry(treeView.Sel ectedNode.Text) ;
and then when declaring the child form I put this: public
editStockCateg ory(string nodeText)

But I'm not sure how to make nodeText available in the child form Load
event.

Arghhh.

Susan


The SelectedNode.To String() doesn't return to value for the Text
attribute of the node. Use SelectedNode.Te xt instead.
But first, before doing that, make sure that a node is selected to
prevent errors.

if (MyTreeview.Sel ectedNode != 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.TextBo x1.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.NodeVa lue = SelectedNode.Te xt

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.NodeVa lue = MyTreeview.Sele ctedNode.Text
if (mainForm.ShowD ialog() == DialogResult.Ok )
{
MyTreeview.Sele ctedNode.Text = mainForm.NodeVa lue;
}

Besides that, one suggestion, do not use "mainForm" as variable name,
since it is not your mainForm :-)

greetz,
Leon
Feb 28 '06 #7
HI,

You pass a reference to the parent form to the child form, also you need to
make accesible the controls you want to have access to (either by declaring
them public or by using properties )

Another possible pattern to update one form from other is using a method
that indicate that a changed was performed and the interface (form's
control) need to be reload with updated data. you can do this by declaring
an interface like

public interface IDataUpdated{ void NewDataSaved(); } and having the parent
class implement it, the child could get a reference to that instance and
after the updated call the method.
This approach is more flexible as you can have several child forms and these
forms need not to be modals. (using DialogResult usually imply that the
child form has to be modal)

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<su************ *@googlemail.co m> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. .
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 ();
stockCategoryNa me.Text =
mainForm.treeVi ew.SelectedNode .ToString();

But mainForm.treeVi ew.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: editStockCatego ry f =
new editStockCatego ry(treeView.Sel ectedNode.Text) ;
and then when declaring the child form I put this: public
editStockCatego ry(string nodeText)

But I'm not sure how to make nodeText available in the child form Load
event.

Arghhh.

Susan

Feb 28 '06 #8

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
HI,

You pass a reference to the parent form to the child form


Then you have created a mutual dependency between the forms. They cannot be
developed, tested or deployed independently.

Use interfaces and/or events.
Mar 1 '06 #9
Hi,

"Nick Hounsome" <nh***@nickhoun some.me.uk> wrote in message
news:qD******** **********@fe3. news.blueyonder .co.uk...

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
wrote in message news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
HI,

You pass a reference to the parent form to the child form


Then you have created a mutual dependency between the forms. They cannot
be developed, tested or deployed independently.

Use interfaces and/or events.


True, you create a dependency, the best way is th use an interface that
expose only the needed public data member that you need


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Mar 1 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1950
by: Will | last post by:
Pardon two post in a row to the newsgroup but I want to try and expedite this, if you guys don't mind helping out... I running Windows XP Pro and wanted to download Python and any additional tools I should consider using as I get going... 1 - Python-2.3.3.exe from www.Python.org 2 - win32all, a collection of Windows-specific extensions including COM support and Pythonwin, an IDE built using Windows components from Mark Hammond's
4
2307
by: blah | last post by:
I m actually a Novice in Python as well as Linux, When i look up things on the internet about Linux Flavours, They are written so complex that it is difficult for me to understand, i am asking if anyone here know of a Linux Distribution that is for beginners (I am a new user of linux, therefore, i dont know what linux will do.) also the flavour must have python so i can work on it too. I will use Vmware Workstation, because Linux and...
4
2244
by: Eggnog | last post by:
Hi, Is there a newsgroups for beginners questions? Cheers, Nawg
6
4069
by: William Foster | last post by:
Does anyone know of a good online tutorial for C# focused on beginners. I have been to many great sites like csharpfriends, csharp-corner etc looking for good tutorials and have had no luck. Any advice would be appreciated. Bill Foster
18
13929
by: John Salerno | last post by:
Hi all. I was hoping some of you could recommend a book or two that would help me get started with the basics of C#. I have a slight knowledge of programming, but basically I want to start out like I know nothing, so I don't skip anything. I considered Microsoft Visual C# .NET Step by Step 2003 by Sharp/Jagger, but then I read a few reviews and it doesn't sound so good. I have XP Home, and I plan to buy only Visual C#, not Visual Studio,...
2
1546
by: =?Utf-8?B?UmFrZXNo?= | last post by:
Hi, I have worked in Windows development for some time and want to learn ASP.Net - Web Application. Can some one redirect me to some site where I can find some good start up for beginners course like Sample Applications with documentation. That would be of great help. Thanks in Advance:
4
2134
by: aman firoz | last post by:
do you people got anything for c beginners..... help me out guys
0
1444
by: Dual_b00t | last post by:
hi i created a site called PHP Together its for beginners also for gurus to help out the beginners if you are learning PHP and feel alone then drop by . ciao Mark
19
4117
by: yltkhuu | last post by:
1. How does having a widely adopted C++ standard help game programmers? 2. What are the advantages ans disadvantages of employing the "using" directive? 3. Why might you define a new name for an existing type? 4. Why are there two versions of the increment operator? What's the difference between them? 5. How can you use constants to improve your code?
6
1510
by: Lars | last post by:
Hi all If this is the wrong list for beginners trouble I apologize. please refer to me the correct list in such case. I am trying to create a simple linked list but I keep getting segmentation errors and I dont know why. I realize that I do not free the allocated memory but the segfault happpens (it seems) with the insert function. Can any one explain ? Regards Lars
0
9564
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.