CanDroid
CanDroid

Reputation: 643

How to set values of user control from class

I have a user control and their are many textbox on it. I add this user control to a different project and I can use it, when I write every property on UserControl. I want to set textbox fields of this user control with using a class. These are my codes:

Class:

namespace IEUserControl
{
     public class IEValue
    {        
        public  string IsEmriNo { get; set; }
        public  string Nevi { get; set; }
        public  string BrutKg { get; set; }        
        public string NetKg { get; set; }        
    }
}

User Control:

namespace IsEmriUserControl
{
    public partial class UC_IsEmri : UserControl
    {
        public UC_IsEmri()
        {
            InitializeComponent();
        }

        //private IsEmriValue _isEmri;


        //public IsEmriValue isEmri
        //{
        //    get
        //    {
        //        return _isEmri;
        //    }

        //    set
        //    {
        //        _isEmri = value;
        //    }

        //}


        public string IsEmriNo
        {
            get { return txtIsEmriNo.Text; }
            set { txtIsEmriNo.Text = value; }
        }
        public string Nevi
        {
            get { return txtNevi.Text; }
            set { txtNevi.Text = value; }
        }
        public string BrutKg
        {
            get { return txtBrutKg.Text; }
            set { txtBrutKg.Text = value; }
        }
        public string NetKg
        {
            get { return txtNetKg.Text; }
            set { txtNetKg.Text = value; }
        }

    }
}

When I use properties, I can set textbox values. However I want to set my textbox values with my Class. Can anyone give me an example setting textbox values with using class? Thank you.

Upvotes: 2

Views: 1947

Answers (1)

Sinatr
Sinatr

Reputation: 21998

Make a method/property like this

public IEValue IE_Value
{
    get
    {
        return new IEValue() {
            IsEmrino = txtIsEmriNo.Text,
            Nevi = txtNevi.Text,
            BrutKg = txtBrutKg.Text,
            NetKg = txtNetKg.Text
        };
    }
    set
    {
        txtIsEmriNo.Text = value.IsEmrino;
        txtNevi.Text = value.Nevi;
        txtBrutKg.Text = value.BrutKg;
        txtNetKg.Text = value.NetKg;
    }
}

Upvotes: 2

Related Questions