Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Assemblies
.NET Core
.NET Standard
Active Directory
ADO.NET
Agile Development
AJAX
Alexa Skills
Algorithms in C#
Android
Angular
Architecture
ArcObject
Artificial Intelligence
ASP.NET
ASP.NET Core
Augmented Reality
Aurelia
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blockchain
Bootstrap
Bot Framework
Business
C#
C# Corner
C, C++, MFC
Career Advice
Chapters
CIO
Cloud
COBOL.NET
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Cortana Development
Cryptocurrency
Cryptography
Crystal Reports
Current Affairs
Custom Controls
Cyber Security
Data Mining
Databases & DBA
Design Patterns & Practices
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
Expression Studio
F#
Files, Directory, IO
Games Programming
GDI+
General
Generative Engine Optimization (GEO)
Google Cloud
Google Development
Graphics Design
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Internet & Web
Internet of Things
Ionic
iOS
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
kotlin
Leadership
Learn .NET
LightSwitch
LINQ
Machine Learning
Microsoft 365
Microsoft Office
Microsoft Phone
Mobile Development
Multithreading
Nano Banana
NetBeans
Networking
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Power BI
Printing in C#
Products
Progressive Web Apps
Project Management
Python
Q#
QlikView
R
React
Reports using C#
Robotics & Hardware
Ruby on Rails
Salesforce
Security
Servers
SharePoint
SignalR
Silverlight
Smart Devices
Software Testing
SQL Language
SQL Server
Startups
String in C#
Swift
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
WCF
Wearables
Web Development
Web Services
Web3
Windows 10
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML Standard
XML
XNA
XSharp
Register
Login
3
Answers
Pass info between two forms
Shawn
18y
1.6k
0
1
Active Directory
Reply
Hello all,
I am coming from a VB .NET background and I am a little confused with how to access another forms properties in C#. Basically I am taking one of the exercises from my VB book and trying to convert to C# to help me learn C#.
Anyhow, here is the task at hand. Form 1 is basically a list view of items that were sold for a particular day. One of the buttons on this form allows the user to open another form to enter the actual items that were sold that day. I have both the interfaces completed, have the second form loading when the user hits the "Enter sales" button on form 1.
However, the next step in my VB book starts the exectution of a do until loop. It accesses the text property of the second form and continuously loops until the text property is empty, meaning the user did not enter another item.
Example: Do Until objAddItemForm.txtItemDescription.Text=""
...process data and add to listview on form 1...
Loop
Ok, so my problem is, how do I access this text field on form 2, to check to see if it is blank, or add its text property to the listview, from form 1?
Thanks for any help,
Shawn
*Edit* - Here is the code I have so far:
Form1
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
namespace
WindowsApplication6
{
public
partial
class
frmTodaysSalesCheck
:
Form
{
public
frmTodaysSalesCheck()
{
InitializeComponent();
}
private
void
btnEnterSales_Click(
object
sender,
EventArgs
e)
{
//Declares objAddItemForm as a new Form
//and opens it in modal form. Modal means
//only the currently activated window is
//accessible for input/action.
Form
objAddItemForm =
new
frmAddItem
();
objAddItemForm.ShowDialog();
}
}
}
Form2
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
namespace
WindowsApplication6
{
public
partial
class
frmAddItem
:
Form
{
public
frmAddItem()
{
InitializeComponent();
}
private
void
btnOk_Click(
object
sender,
EventArgs
e)
{
this
.Close();
}
}
}
Right now the second form is just closing when the user clicks the Ok button. What I need to do is read the textbox entry on form2 and add it to the listview on form1. Any ideas how to do this?
Thanks again,
Shawn
Post
Reset
Cancel
Answers (
3
)
Related Discussion