Avatar of ziwez0
ziwez0 asked on

Class

Hi, im still getting my head round some of this stuff so please bare with me.

ive got a main form, and inside that form i have a User Control form (which ill call ucSearch)
ucSearch has a dropdownlist and a button which does the following:
private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                UserID = new csUsers();
                UserID.CustomerID = Convert.ToInt32(cboCustomerLastName.SelectedValue);
                MessageBox.Show(UserID.CustomerID.ToString(), "ID of selected client");
            }
            catch
            {
throw;
            }
        }

ive called a class which does the following
public class csUsers
    {
       
        private int xCustomerID;

        public int CustomerID
        {
            get
            {
                return xCustomerID;
            }
            set
            {
                xCustomerID = value;
            }
        }
}
}

but how can i access that value on my main form? i basically want to store this value so lots of other forms can access it, perahps ive done this all wrong, if so please show me the best way to do it.
I just want to be able to get and set the value and easily get access to that value;
thanks
C#

Avatar of undefined
Last Comment
ziwez0

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
lucky_james

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Jaime Olivares

you can create a static object for your data class, a good place to put inside is the Program class (which is static too).
So you can access from anywhere in your aplication as:
Program.UserID
ASKER
ziwez0

Thanks, making it static was what i needed, I actually printed out the def of the word 'static' just never got round to reading it.

thanks
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck