473,503 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open frmDataGrid from Form # 1

145 New Member
This code on my form # 1 button.

Expand|Select|Wrap|Line Numbers
  1.         If txtDate.MaskCompleted = True Then
  2.             Dim form As New frmDataGrid
  3.             form.Show()
  4.         Else
  5.             MessageBox.Show("You must input a date")
  6.             Exit Sub
  7.         End If
I added a form "frmDataGrid" and used vb.net toolbox to create datagrid. I did pick data source and it's a Stored Procedure(@tDate is require parameter). How do I pass a parameter from my form #1 (txtDate) to frmDataGrid?
May 29 '08 #1
3 981
dfarney
6 New Member
This code on my form # 1 button.

Expand|Select|Wrap|Line Numbers
  1.         If txtDate.MaskCompleted = True Then
  2.             Dim form As New frmDataGrid
  3.             form.Show()
  4.         Else
  5.             MessageBox.Show("You must input a date")
  6.             Exit Sub
  7.         End If
I added a form "frmDataGrid" and used vb.net toolbox to create datagrid. I did pick data source and it's a Stored Procedure(@tDate is require parameter). How do I pass a parameter from my form #1 (txtDate) to frmDataGrid?
In C#:

create your frmDataGrid class like so...
Expand|Select|Wrap|Line Numbers
  1. public partial class frmDataGrid : Form
  2. {
  3.     private string date;
  4.  
  5.     public frmDataGrid()
  6.     {
  7.         InitializeComponent();
  8.     }
  9.  
  10.     public frmDataGrid(string _date)
  11.     {
  12.         InitializeComponent();
  13.         date = _date;
  14.     }
  15. }
Call it like so...
Expand|Select|Wrap|Line Numbers
  1. if (txtDate.MaskCompleted)
  2. {
  3.     frmDataGrid frm = new frmDataGrid(txtDate.Text);
  4.     frm.Show();
  5. }
  6. else
  7. {
  8.     MessageBox.Show("C# is far superior to VB :)");
  9. }
May 29 '08 #2
Curtis Rutland
3,256 Recognized Expert Specialist
How do I pass a parameter from my form #1 (txtDate) to frmDataGrid?
There are two ways to do this. One way to do this is to modify your frmDataGrid's constructor. Another way is to add a Public member to frmDataGrid, and after you instantiate it, set the value.

I'll show you the first way. Add a parameter to the constructor. If you did not define a constructor, you need to add one.

So if you wanted to pass a String for example, do this in frmDataGrid:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private paramS as String
  3.  
  4. Public Sub New(s as String)
  5.         ' This call is required by the Windows Form Designer.
  6.         InitializeComponent()
  7.  
  8.         ' Add any initialization after the InitializeComponent() call.
  9.         paramS = s
  10. End Sub
  11.  
And you would have to change the way you call the form:
Expand|Select|Wrap|Line Numbers
  1. Dim form as New frmDataGrid("whatever string you want to pass")
  2. form.Show()
  3.  
May 29 '08 #3
dorandoran
145 New Member
Thank you guyz for all your help. Really good tips and code. I truly appreciate it.

Thanks
May 30 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
462
by: Konstantin | last post by:
Can someone help me figure out a way to open a form only once in an MDI app. I have an MDI app that contains several forms. I use each form depending on the type of document that the user needs...
2
4084
by: Julia Baresch | last post by:
Hi everyone, As some of you may know, we've been having trouble with an unrecognized database format error. Today I installed an unfinished project on the workstation of one of my users. ...
1
2950
by: 4004 | last post by:
I would like to open a columnar form (so I can see all the details) from a datasheet form (so I can see what is there) but keep the same recordset and current record. I can do the recordset set...
1
10036
by: petersk | last post by:
Firstly I am an older person trying to teach myself to create a project and teach myself Access VBA programming along the way. I anticipate a number of problems I will need help with but here...
3
2792
by: rdemyan via AccessMonster.com | last post by:
My application is split into a front end and back end. Each user has their own copy of the front end. There are a few forms I only want to be open for one user at a time. So I've implemented the...
13
2915
by: Academic | last post by:
I have a MDI form, sometimes child forms and sometimes forms that are neither If I close the app the child forms closing and closed event happens followed by the Mdi form receiving the...
6
2631
by: Bob Alston | last post by:
Looking for someone with experience building apps with multiple instances of forms open. I am building an app for a nonprofit organizations case workers. They provide services to the elderly. ...
19
19024
by: =?Utf-8?B?R3JlZw==?= | last post by:
How can I tell via code if a Form is already open. Each time my forms load I have some initialization code that runs, but if the form is already open and hidden I don't want that initialization...
5
7614
by: billa856 | last post by:
Hi, My project is in MS Access 2002. In that I want to open one form multiple times. I put one button on my main form. Now whenever I click on that button than form will be open. Now when I...
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7072
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...
0
7319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6979
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...
0
5570
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,...
1
4998
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...
0
4666
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...
0
3160
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...
0
1498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.