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 Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
3
Answers
Pass info between two forms
Shawn
17y
1.9k
1
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
)
Next Recommended Forum
Throughput/Design problem
Compare string / wildcards???