?
Solved

UserControl Textbox

Posted on 2006-04-04
8
Medium Priority
?
1,605 Views
Last Modified: 2008-03-03
I have created a usercontrol text with some additional data binding properties. How can i get the text property of the textbox to display the displaymember whenever the selectedvalue is changed?

Matthew

namespace WindowsApplication1
{
    [System.ComponentModel.LookupBindingProperties("DataSource", "DisplayMember", "ValueMember", "LookupMember")]
    [System.ComponentModel.DefaultBindingProperty("SelectedValue")]
    public partial class UserControl1 : TextBox
    {
        private Int32 selectedValue;
        private string valueMember;
        private string displayMember;
        private object dataSource;

        public object DataSource
        {
            get { return dataSource; }
            set { dataSource = value; }
        }

        public string DisplayMember
        {
            get { return displayMember; }
            set { displayMember = value; }
        }

        public string ValueMember
        {
            get { return valueMember; }
            set { valueMember = value; }
        }

        public Int32 SelectedValue
        {
            get { return selectedValue; }
            set { selectedValue = value; }
        }

        public string LookupMember
        {
            get { return selectedValue.ToString(); }
            set { selectedValue = Convert.ToInt32(value); }
        }

        public UserControl1()
        {
            InitializeComponent();
        }
    }
}
0
Comment
Question by:progTiger
7 Comments
 
LVL 10

Expert Comment

by:athapa
ID: 16377267
Seems like this should work!
AT

        public string DisplayMember
        {
            get { return displayMember; }
            set { displayMember = value;
                    this.Text = displayMember;
                  }
        }
0
 

Author Comment

by:progTiger
ID: 16384810
that just diplyaed the name of the displaymember. I should have clearified more, I want text property to diplay the data stored in the displaymember cell.

Matthew
0
 
LVL 10

Expert Comment

by:tpwells
ID: 16391572
if you are needing to display the SelectedValue when it changes do what athapa suggested but on the SelectedValue property

        public Int32 SelectedValue
        {
            get { return selectedValue; }
            set { selectedValue = value;
                    this.Text=selectedValue;
                 }
        }
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 10

Expert Comment

by:tpwells
ID: 16391627
you also need to change the reference to selectedValue this property:

       public string LookupMember
        {
            get { return selectedValue.ToString(); }
            set { selectedValue = Convert.ToInt32(value); }
        }

to "SelectedValue" with a capital "S" so it will call the property and assign the Text properly in it's property call
0
 

Author Comment

by:progTiger
ID: 16393793
that just displays selected value. I need the text property to display the data stored within the displaymember data column.
0
 

Author Comment

by:progTiger
ID: 16394250
figured it out, here what i did.

Matthew

    public partial class LookupTextBox : TextBox
    {
        private Int32 selectedValue;
        private string valueMember;
        private string displayMember;
        private DataTable dt;

        public LookupTextBox()
        {
            InitializeComponent();
        }

        public DataTable DT
        {
            get { return dt; }
            set { dt = value; }
        }

        public string ValueMember
        {
            get { return valueMember; }
            set { valueMember = value; }
        }

        public string DisplayMember
        {
            get { return displayMember; }
            set { displayMember = value; }
        }

        public Int32 SelectedValue
        {
            get { return selectedValue; }
            set
            {
                selectedValue = value;
                if (displayMember != null)
                {
                    try { this.Text = dt.Rows.Find(selectedValue)[displayMember].ToString(); }
                    catch { }
                }
            }
        }
    }
0
 

Accepted Solution

by:
GranMod earned 0 total points
ID: 16637269
PAQed with points refunded (500)

GranMod
Community Support Moderator
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question