Creating a dialog box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear Anyone,

While most of you will laugh at the fundamental nature of my question, I am
a bit stuck.
I am a reasonable VC++ programmer trying to make the switch to C#. I am
trying to create a simple app in which the user selects a list item,
double-clicks it and then a dialog box is created to show additional
information.
My problem is that I can't seem to get access to the label or text controls
within the newly created dialog box.
Thus my OnDoubleClick() looks like this:

OnDoubleClick()
{
NewDialog D;
D = new NewDialog();
D.ShowDialog();
/* I would like to poplate some controls here */
}

Any help really appreciated.

Thanks
Greg
 
Greg,

You have two general ways of accomplishing this, as I see it:
1) In your design-time view of the dialog box you are creating, select
the UI controls you wish to populate and change their Modifiers property to
public in the Properties window. That will allow you to access the ListBox,
RadioButton, etc., vars that .NET adds to your dialog class from outside
that class, thereby violating just about every object-oriented principle
there is.
2) Give you dialog a constructor in wish you pass the information you
wish to see displayed in the dialog box. If there are a jillion settings,
create a helper class with copies of those settings, and pass that. In many
(most?) cases, you will already have an object class that represents the
thing being edited. For example,

public NewDialog (InventoryList anInventory)
{
lblNumParts.Text = anInventory.Count.ToString();
foreach (Part p in InventoryList)
listbox.Items.Add(String.Format("{0}\t{1}", p.PartNumber,
p.Description);
}

OnDoubleClick()
{
InventoryList tempCopy = (InventoryList)
masterInventoryList.Clone();

NewDialog dlg = new NewDialog(tempCopy);
if (dlg.ShowDialog() == DialogResult.OK)
masterInventoryList.ApplyNewSettings(tempCopy);
}
Using this way, you can replace your ListBox with a ListView in the
dialog, and you won't have to change your calling code.


PC
 
Thanks Philip. It used to be so easy in VC++. I'm really struggling with C#.
I can't even find any decent textbooks. I'll give it a go.
Thanks
Greg
 
Trust me, Greg, once you're over the learning hump, you'll find C# and .NET
_much_ easier

PC
 
Back
Top