473,320 Members | 2,164 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,320 software developers and data experts.

datasets on multiple forms

Sorry for all the posts - Im new to c# and oop and and having a tough time
geting my head around some of this stuff. (I tell you Im surprised my
monitor has lasted this long, Ive been tempted many times to put the
keyboard through it)

I have this dataset on my main form which i need exposed to another form. I
have comboboxes that need to be bound to this dataset. I have tried creating
a new dataset on the new form and what happens is the dialog box pops up
with the option of making it typed or untyped.
the wizard has picked up the dataset from the main form and when I click OK
see the dataset created which has the same name as the dataset on the main
form.

Now when I set the datasource and displaymember on the combobox I can see
all the tables and columns and simply set these values accordingly.

When I run the app and open that form, the comboboxes are empty.

Some posts I have found say to make the dataset public and pass it into the
other form but I dont know how to do this.

Thanks again,
Grant
Nov 16 '05 #1
8 1869
I think you hit the nail on the head when you said that you need it
"Exposed".

Use a property to expose it programatically from the MainForm:
#### Sue Doe code #######

In the main form:

public DataSet MainDataSet
{
get { return this.whateverDataSet; }
}

Now, when you create the other form, pass a reference to you main form and
keep it as a member variable. ie the constructor:

public NewForm(Form parentForm) : Windows.Forms.Form
{
this.parentForm = parentForm;
}

Now in the body of your code you can access the SAME dataSet with

myDataBoundControl.DataSource = parentForm.MainDataSet;

######### End ###########

"Grant" <gp*****@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Sorry for all the posts - Im new to c# and oop and and having a tough time
geting my head around some of this stuff. (I tell you Im surprised my
monitor has lasted this long, Ive been tempted many times to put the
keyboard through it)

I have this dataset on my main form which i need exposed to another form. I have comboboxes that need to be bound to this dataset. I have tried creating a new dataset on the new form and what happens is the dialog box pops up
with the option of making it typed or untyped.
the wizard has picked up the dataset from the main form and when I click OK see the dataset created which has the same name as the dataset on the main
form.

Now when I set the datasource and displaymember on the combobox I can see
all the tables and columns and simply set these values accordingly.

When I run the app and open that form, the comboboxes are empty.

Some posts I have found say to make the dataset public and pass it into the other form but I dont know how to do this.

Thanks again,
Grant

Nov 16 '05 #2
Hi Grant,

If you create the other forms from your main form, you can simply pass the reference to the dataset in the constructor of your other form(s);

class MainForm()
{
DataSet ds;

SomeMethod()
{
OtherForm of = new OtherForm(ds);
of.Show();
}
}

class OtherForm
{
ComboBox comboBox1;
public OtherForm(DataSet ds)
{
InitializeComponent(); // initialize stuff

comboBox1.DataSource = ds;
comboBox1.DisplayMember = "Table1.Column1";
}
}

This will let you use the dataset in main form to fill values in comboBox1.
Note, this code assumes ds have a datatable named "Table1" and that this datatable has a column named "Column1";

Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3
Thanks for the reply. In my new form I have the following:

public class NewAgencyForm : System.Windows.Forms.Form
- and -
public NewAgencyForm()

Where do I put this bit:
public NewForm(Form parentForm) : Windows.Forms.Form
{
this.parentForm = parentForm;
}

When I call the new form with:
NewAgencyForm frm = new NewAgencyForm()
-do I instead say:
NewAgencyForm frm = new NewAgencyForm(this)

"Duncan Mole" <___@____.com> wrote in message
news:uY**************@TK2MSFTNGP12.phx.gbl...
I think you hit the nail on the head when you said that you need it
"Exposed".

Use a property to expose it programatically from the MainForm:
#### Sue Doe code #######

In the main form:

public DataSet MainDataSet
{
get { return this.whateverDataSet; }
}

Now, when you create the other form, pass a reference to you main form and
keep it as a member variable. ie the constructor:

public NewForm(Form parentForm) : Windows.Forms.Form
{
this.parentForm = parentForm;
}

Now in the body of your code you can access the SAME dataSet with

myDataBoundControl.DataSource = parentForm.MainDataSet;

######### End ###########

"Grant" <gp*****@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Sorry for all the posts - Im new to c# and oop and and having a tough
time
geting my head around some of this stuff. (I tell you Im surprised my
monitor has lasted this long, Ive been tempted many times to put the
keyboard through it)

I have this dataset on my main form which i need exposed to another form.

I
have comboboxes that need to be bound to this dataset. I have tried

creating
a new dataset on the new form and what happens is the dialog box pops up
with the option of making it typed or untyped.
the wizard has picked up the dataset from the main form and when I click

OK
see the dataset created which has the same name as the dataset on the
main
form.

Now when I set the datasource and displaymember on the combobox I can see
all the tables and columns and simply set these values accordingly.

When I run the app and open that form, the comboboxes are empty.

Some posts I have found say to make the dataset public and pass it into

the
other form but I dont know how to do this.

Thanks again,
Grant


Nov 16 '05 #4
Sorry, grabaged that up a bit and put the class extension stuff in the
constuctor!!

you need:

public NewAgencyForm(Form parentForm)
{
this.parentForm = parentForm;
}

and yes you cal the constuctor with:

NewAgencyForm frm = new NewAgencyForm(this)

"Grant" <gp*****@hotmail.com> wrote in message
news:O5**************@TK2MSFTNGP09.phx.gbl...
Thanks for the reply. In my new form I have the following:

public class NewAgencyForm : System.Windows.Forms.Form
- and -
public NewAgencyForm()

Where do I put this bit:
public NewForm(Form parentForm) : Windows.Forms.Form
{
this.parentForm = parentForm;
}

When I call the new form with:
NewAgencyForm frm = new NewAgencyForm()
-do I instead say:
NewAgencyForm frm = new NewAgencyForm(this)

"Duncan Mole" <___@____.com> wrote in message
news:uY**************@TK2MSFTNGP12.phx.gbl...
I think you hit the nail on the head when you said that you need it
"Exposed".

Use a property to expose it programatically from the MainForm:
#### Sue Doe code #######

In the main form:

public DataSet MainDataSet
{
get { return this.whateverDataSet; }
}

Now, when you create the other form, pass a reference to you main form and keep it as a member variable. ie the constructor:

public NewForm(Form parentForm) : Windows.Forms.Form
{
this.parentForm = parentForm;
}

Now in the body of your code you can access the SAME dataSet with

myDataBoundControl.DataSource = parentForm.MainDataSet;

######### End ###########

"Grant" <gp*****@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
Sorry for all the posts - Im new to c# and oop and and having a tough
time
geting my head around some of this stuff. (I tell you Im surprised my
monitor has lasted this long, Ive been tempted many times to put the
keyboard through it)

I have this dataset on my main form which i need exposed to another form.
I
have comboboxes that need to be bound to this dataset. I have tried

creating
a new dataset on the new form and what happens is the dialog box pops
up with the option of making it typed or untyped.
the wizard has picked up the dataset from the main form and when I click OK
see the dataset created which has the same name as the dataset on the
main
form.

Now when I set the datasource and displaymember on the combobox I can

see all the tables and columns and simply set these values accordingly.

When I run the app and open that form, the comboboxes are empty.

Some posts I have found say to make the dataset public and pass it into

the
other form but I dont know how to do this.

Thanks again,
Grant



Nov 16 '05 #5
I put that in and get the error that newagencyform does not contain a
definition for 'parentForm'.

I had a look on msdn for that parentForm function and tried the following:
DataSet dataSet = ((MainForm)this.ParentForm)agencyDataset

It didnt like that though. All I get is default functions like
'acceptchanges' and so on.

"Duncan Mole" <___@____.com> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
Sorry, grabaged that up a bit and put the class extension stuff in the
constuctor!!

you need:

public NewAgencyForm(Form parentForm)
{
this.parentForm = parentForm;
}

and yes you cal the constuctor with:

NewAgencyForm frm = new NewAgencyForm(this)

"Grant" <gp*****@hotmail.com> wrote in message
news:O5**************@TK2MSFTNGP09.phx.gbl...
Thanks for the reply. In my new form I have the following:

public class NewAgencyForm : System.Windows.Forms.Form
- and -
public NewAgencyForm()

Where do I put this bit:
public NewForm(Form parentForm) : Windows.Forms.Form
{
this.parentForm = parentForm;
}

When I call the new form with:
NewAgencyForm frm = new NewAgencyForm()
-do I instead say:
NewAgencyForm frm = new NewAgencyForm(this)

"Duncan Mole" <___@____.com> wrote in message
news:uY**************@TK2MSFTNGP12.phx.gbl...
>I think you hit the nail on the head when you said that you need it
> "Exposed".
>
> Use a property to expose it programatically from the MainForm:
>
>
> #### Sue Doe code #######
>
> In the main form:
>
> public DataSet MainDataSet
> {
> get { return this.whateverDataSet; }
> }
>
> Now, when you create the other form, pass a reference to you main form and > keep it as a member variable. ie the constructor:
>
> public NewForm(Form parentForm) : Windows.Forms.Form
> {
> this.parentForm = parentForm;
> }
>
> Now in the body of your code you can access the SAME dataSet with
>
> myDataBoundControl.DataSource = parentForm.MainDataSet;
>
> ######### End ###########
>
>
>
> "Grant" <gp*****@hotmail.com> wrote in message
> news:%2***************@TK2MSFTNGP09.phx.gbl...
>> Sorry for all the posts - Im new to c# and oop and and having a tough
>> time
>> geting my head around some of this stuff. (I tell you Im surprised my
>> monitor has lasted this long, Ive been tempted many times to put the
>> keyboard through it)
>>
>> I have this dataset on my main form which i need exposed to another form. > I
>> have comboboxes that need to be bound to this dataset. I have tried
> creating
>> a new dataset on the new form and what happens is the dialog box pops up >> with the option of making it typed or untyped.
>> the wizard has picked up the dataset from the main form and when I click > OK
>> see the dataset created which has the same name as the dataset on the
>> main
>> form.
>>
>> Now when I set the datasource and displaymember on the combobox I can see >> all the tables and columns and simply set these values accordingly.
>>
>> When I run the app and open that form, the comboboxes are empty.
>>
>> Some posts I have found say to make the dataset public and pass it
>> into
> the
>> other form but I dont know how to do this.
>>
>> Thanks again,
>> Grant
>>
>>
>
>



Nov 16 '05 #6
On Fri, 28 May 2004 20:55:28 +1000, Grant <gp*****@hotmail.com> wrote:
I put that in and get the error that newagencyform does not contain a
definition for 'parentForm'.

I had a look on msdn for that parentForm function and tried the following:
DataSet dataSet = ((MainForm)this.ParentForm)agencyDataset


((MainForm)this.ParentForm).agencyDataSet

You only missed a dot :)

Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #7
Nice one! That worked a bomb! Just a little slow when opening the new form
for some reason but I can live with that.

Thank you.

"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opr8pexglkklbvpo@morten_x.edunord...
Hi Grant,

If you create the other forms from your main form, you can simply pass the
reference to the dataset in the constructor of your other form(s);

class MainForm()
{
DataSet ds;

SomeMethod()
{
OtherForm of = new OtherForm(ds);
of.Show();
}
}

class OtherForm
{
ComboBox comboBox1;
public OtherForm(DataSet ds)
{
InitializeComponent(); // initialize stuff

comboBox1.DataSource = ds;
comboBox1.DisplayMember = "Table1.Column1"; }
}

This will let you use the dataset in main form to fill values in
comboBox1.
Note, this code assumes ds have a datatable named "Table1" and that this
datatable has a column named "Column1";

Happy coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #8
You don't need to cast it.

in the class you need a member variable for your reference to parentForm.

eg private Form parentForm;

This is what is et in the constuctor. Provided you called the DataSet
property in you main form "agencyDataSet" then the following should be fine:

DataSet dataSet = this.ParentForm.agencyDataset

If not post your code

"Grant" <gp*****@hotmail.com> wrote in message
news:e9**************@TK2MSFTNGP12.phx.gbl...
I put that in and get the error that newagencyform does not contain a
definition for 'parentForm'.

I had a look on msdn for that parentForm function and tried the following:
DataSet dataSet = ((MainForm)this.ParentForm)agencyDataset

It didnt like that though. All I get is default functions like
'acceptchanges' and so on.

"Duncan Mole" <___@____.com> wrote in message
news:uP**************@TK2MSFTNGP09.phx.gbl...
Sorry, grabaged that up a bit and put the class extension stuff in the
constuctor!!

you need:

public NewAgencyForm(Form parentForm)
{
this.parentForm = parentForm;
}

and yes you cal the constuctor with:

NewAgencyForm frm = new NewAgencyForm(this)

"Grant" <gp*****@hotmail.com> wrote in message
news:O5**************@TK2MSFTNGP09.phx.gbl...
Thanks for the reply. In my new form I have the following:

public class NewAgencyForm : System.Windows.Forms.Form
- and -
public NewAgencyForm()

Where do I put this bit:
public NewForm(Form parentForm) : Windows.Forms.Form
{
this.parentForm = parentForm;
}

When I call the new form with:
NewAgencyForm frm = new NewAgencyForm()
-do I instead say:
NewAgencyForm frm = new NewAgencyForm(this)

"Duncan Mole" <___@____.com> wrote in message
news:uY**************@TK2MSFTNGP12.phx.gbl...
>I think you hit the nail on the head when you said that you need it
> "Exposed".
>
> Use a property to expose it programatically from the MainForm:
>
>
> #### Sue Doe code #######
>
> In the main form:
>
> public DataSet MainDataSet
> {
> get { return this.whateverDataSet; }
> }
>
> Now, when you create the other form, pass a reference to you main form
and
> keep it as a member variable. ie the constructor:
>
> public NewForm(Form parentForm) : Windows.Forms.Form
> {
> this.parentForm = parentForm;
> }
>
> Now in the body of your code you can access the SAME dataSet with
>
> myDataBoundControl.DataSource = parentForm.MainDataSet;
>
> ######### End ###########
>
>
>
> "Grant" <gp*****@hotmail.com> wrote in message
> news:%2***************@TK2MSFTNGP09.phx.gbl...
>> Sorry for all the posts - Im new to c# and oop and and having a
tough >> time
>> geting my head around some of this stuff. (I tell you Im surprised my >> monitor has lasted this long, Ive been tempted many times to put the
>> keyboard through it)
>>
>> I have this dataset on my main form which i need exposed to another

form.
> I
>> have comboboxes that need to be bound to this dataset. I have tried
> creating
>> a new dataset on the new form and what happens is the dialog box pops up
>> with the option of making it typed or untyped.
>> the wizard has picked up the dataset from the main form and when I

click
> OK
>> see the dataset created which has the same name as the dataset on
the >> main
>> form.
>>
>> Now when I set the datasource and displaymember on the combobox I

can see
>> all the tables and columns and simply set these values accordingly.
>>
>> When I run the app and open that form, the comboboxes are empty.
>>
>> Some posts I have found say to make the dataset public and pass it
>> into
> the
>> other form but I dont know how to do this.
>>
>> Thanks again,
>> Grant
>>
>>
>
>



Nov 16 '05 #9

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

Similar topics

2
by: yoelgold | last post by:
Hi I want to start writing a new site. It will include 3 forms that will collect information from the user. I know how to keep the info in sessions etc. my question is about the design of the...
1
by: Chris Beach | last post by:
Hi, I have a JSP page with several forms on it. Some of these forms are generated dynamically, and each of them submits some information to a database. Handling one form is easy, as I can...
1
by: Don | last post by:
hi in the past (vb 5.0) is used to create applications with multiple forms. i would hide and/or show the appropriate form depending on user input. now i'm using vb.net (still getting used to it)...
8
by: TJS | last post by:
what are folks doing to get around limitation of one server form per page ?
7
by: Jeff | last post by:
I plan to write a Windows Forms MDI application for a medical office. Users must be able to select a patient and view related information on multiple forms; with1-4 forms opened at the same time...
0
by: question | last post by:
Hi! I have a requirement where I need to display multiple forms one after the other like a slide show. These are in the same application. Basicall on selection of a menu item it should start...
5
by: c676228 | last post by:
Hi everyone, my colleagues are thinking about have three insurance plans on one asp page: I simplify the plan as follow: text box:number of people plan1 plan2 plan3
3
by: Yehia A.Salam | last post by:
hello, I have to deal with the weird limitation of asp.net, as I need to have multiple forms on my page, well three at least actually, one for the login, one for the search engine, and another...
2
by: =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post by:
Hi, I am going to write a large application using Visual Studio C#. I am going to use only one Form as main menu and go to other pages by cliking on next button in each page. I dont want to create...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
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

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.