none
Selected Data from Combobox displayed in Textbox (C#)

    Question

  • I am pretty new to the C# development.  I have a couple problems with the combobox.  First being that I am loading the combobox with data from a Access Database.  I want to select a particular one and display that selected item in a textbox.  I'm sure this is really easy but I am having a problem doing it.  It is basically like whatever is selected in the combobox I want to see the same text in a textbox.

    The second issue is ... when I load the combobox with the data it automatically comes up with the first one in the list in the combobox.  I would like it to be empty until it is selected.  Basically, would like an unselected item as well in the first position.  It is like when you use the unbound mode and manually enter them in ... you can make the first selection empty.  But since I am loading it from a database ... there is no empty spots.

    Any help is appreciated.  Thanks.
    S
    Friday, November 13, 2009 10:40 PM

Answers

  • Have you tried the SelectedItem property?  My combo box is populated with static values, and I just use the Text, which works in my situation.  Also, are you setting your text box in the SelectionChanged event?

    this

     

    .comboBox1.SelectedItem.ToString();

    • Marked as answer by Roahn Luo Friday, November 20, 2009 6:33 AM
    Saturday, November 14, 2009 12:14 AM

All replies

  • Try setting the SelectedIndex property to -1. That should clear your selection.

    Hope this helps.
    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Friday, November 13, 2009 11:02 PM
  • That took care of the one issue ... thanks ... now I just need to figure out how to get the text data of the selected item from the combobox down to the textbox.

    Thanks again.

    S
    Friday, November 13, 2009 11:23 PM
  • Take a look at the selection events. I don't have my system handy to look up their exact names (which is why I did not reply to this part).

    Something like SelectionChangeCommited, or SelectedIndexChanged.

    In that event, put the text from the combobox into the textbox.

    Hope this helps get you started!
    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Friday, November 13, 2009 11:38 PM
  • Well, I tried that earlier ... but since it is being filled by an Access database table it puts this into the textbox:  "System.Data.DataRowView"

    here is the code I am using to write it to the textbox: 

    this

     

    .textBox1.Text = this.comboBox1.Text.ToString();

    Friday, November 13, 2009 11:49 PM
  • Have you tried the SelectedItem property?  My combo box is populated with static values, and I just use the Text, which works in my situation.  Also, are you setting your text box in the SelectionChanged event?

    this

     

    .comboBox1.SelectedItem.ToString();

    • Marked as answer by Roahn Luo Friday, November 20, 2009 6:33 AM
    Saturday, November 14, 2009 12:14 AM
  • Hello vbplaya,

    Please try Chris' suggestion, could we get the correct data to be displayed? If you don't mind, I'm going to mark Chris' reply as answer. If there are still some issues, please give us feedback and change the thread's type back to question.

    Thanks a lot!
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Friday, November 20, 2009 6:37 AM