473,326 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Creating a dialog box

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
Nov 16 '05 #1
3 12021
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

"Greg Horwood" <Gr*********@discussions.microsoft.com> wrote in message
news:68**********************************@microsof t.com...
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

Nov 16 '05 #2
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

"Philip Coveney" wrote:
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

"Greg Horwood" <Gr*********@discussions.microsoft.com> wrote in message
news:68**********************************@microsof t.com...
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


Nov 16 '05 #3
Trust me, Greg, once you're over the learning hump, you'll find C# and .NET
_much_ easier

PC
Nov 16 '05 #4

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

Similar topics

1
by: Matthew Clubb | last post by:
Hi, I need help developing an expanding form I've decided that a use of PHP, Mysql and Javascript is the best platform for creating a selection of database interfaces which I'm trying to build...
1
by: dave | last post by:
I first started using HCW.exe to compile .rtf filew created with MS Word a couple of weeks ago. I used the file | new menu then selected New project in the dialog box and everything worked as...
3
by: Nicolae Fieraru | last post by:
Hi All, I just start learning Visual Studio 2002. I use C++ and I want to create a dialog application. For this I select File->New Project->Win32 Project and in the Application Settings I chose...
24
by: jonathon | last post by:
Hi all, I have a web app with a popup window for entering data. I don't want to access the web every time this window is opened, as most of the app is AJAX. But I can't figure out how to open...
3
by: Bullvyi | last post by:
We have a old VBA app that create 3 linked tables to SQL server. However for whatever reason now whenever the code tries to create these linked tables, a dialog box comes up prompting for a server...
2
by: | last post by:
Hi all, I have vs.net 2003 locally installed on my XP PRO machine. I have a web server on the LAN which has a website configured at http://services. This is accessible via my web browser and...
11
by: melon | last post by:
Let's say, I have a form class... public class MainForm : Form { private CustomClass cc; public MainForm() { DoSomething() InitializeComponent(); } /// Do something more
3
by: teephish | last post by:
Hello, I'm currently in the process of creating a small access database and I'm having some problems with creating a customized search. I would like the user to be able to search a record by last...
1
by: dhanashivam | last post by:
Hi All, I have developed a VC+ dll file which provides a product key for my msi setup file. This VC++ dll work fine together with my setup file. but, my problem is, i have given a message box...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.