5 Replies - 11700 Views - Last Post: 29 December 2011 - 02:09 PM Rate Topic: -----

#1 sidyusuf  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 15-September 11

match combobox item with the text in textbox and set selected item

Posted 29 December 2011 - 02:43 AM

hi frnds ,
i have a combobox containing countries name and their codes like INDIA:CNT001
then i have a textbox that store the code of country i.e CNT001(fetching from database)
Now i want to match that code with the combobox code so that the combobox is set to that item when i click a button.
i m using vb.net and sql server as database.
i hav attached an image as an example.

Attached image(s)

  • Attached Image

Is This A Good Question/Topic? 0
  • +

Replies To: match combobox item with the text in textbox and set selected item

#2 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5625
  • View blog
  • Posts: 12,061
  • Joined: 02-June 10

Re: match combobox item with the text in textbox and set selected item

Posted 29 December 2011 - 08:03 AM

What have to you tried to code so far?
What part of what you have tried isn't working?
Are you getting error messages, or is it just not giving you the results you wanted?

(In other words, you at least have to make and show us your good faith effort to do your own coding. We are here to help you, not do it for you.)

Suggestion:
Don't replace lines of code that don't work. Instead comment them out and put your new attemps below that. This will keep you from re-trying the same ideas over and over. Also, when you come back to us saying "I've tried this 100 different ways and still can't get it", we can actually see what you tried. So often a failed attempt is very very close and just needs a little nudge in the right direction. So if we can say "See what you did in attempt 3... blah blah" it helps a lot

// Try #1 - May 1, 0900hrs
//    code
//    code  
//    code
// Try #2 - May 2, 1700hrs   Okay, plan B.  What if I do it *this* way
//    code
//    code  
//    code
// Try #14 - May 3, 0500hrs after 5 cans of RedBull.  Maybe I should get some sleep. I can't think of anything else but this last idea
    code
    code  
    code


If you are using Visual Studio you can select a block of lines and hit control+k control+c (Kode comment) to comment it out. control+k control+u (Kode Uncomment) to uncomment a selected block.
Was This Post Helpful? 0
  • +
  • -

#3 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: match combobox item with the text in textbox and set selected item

Posted 29 December 2011 - 01:40 PM

Or put an apostrophe in front of the code (at least in VB)
Was This Post Helpful? 0
  • +
  • -

#4 ToshNeox  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 100
  • Joined: 10-December 11

Re: match combobox item with the text in textbox and set selected item

Posted 29 December 2011 - 01:42 PM

I think that you can do
comboBox.SelectedItem = "Abc"
Which should change the selected item to one called 'Abc'.

For example:
A combobox with an item 'INDIA:CNT001' then you can do:
comboBox.SelectedItem = "INDIA:CNT001"
Was This Post Helpful? 0
  • +
  • -

#5 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: match combobox item with the text in textbox and set selected item

Posted 29 December 2011 - 02:03 PM

Well you could use FindString:
http://msdn.microsof...y/a8179s15.aspx
And then set the index of the combo box to the result.
Was This Post Helpful? 0
  • +
  • -

#6 ToshNeox  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 100
  • Joined: 10-December 11

Re: match combobox item with the text in textbox and set selected item

Posted 29 December 2011 - 02:09 PM

Here's a good reference to my post:
http://www.programme...-box-with-code/
(Look at the bottom)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1