473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

How to set selected item when combobox is bound to dictionary

This seems like it should be fairly simple, but it has me stumped.

I have a combobox that is bound to a dictionary. I also have a datagridview that is supposed to populate the combobox when a row is selected. The gridview displays the key which is numeric and I want the combobox to display the value which is text. I thought this would work:
Expand|Select|Wrap|Line Numbers
  1. cboSourceID.SelectedItem = dgvInfoware.Item(3, rowIndex).Value
  2.  
It doesn't. I also thought maybe I needed to set the value member to the new key, but that deleted everything in the combobox.
Dec 13 '12 #1
2 3379
PsychoCoder
465 Expert Mod 256MB
Not knowing exactly how you're binding your ComboBox to your Dictionary have you tried the SelectedValue of the combobox, like this:

Expand|Select|Wrap|Line Numbers
  1. cboSourceID.SelectedValue = dgvInfoware.Item(3, rowIndex).Value
Dec 13 '12 #2
That doesn't work either. This is how I did the bind.
Expand|Select|Wrap|Line Numbers
  1.  cboSourceID.BindingContext = New BindingContext
  2.  cboSourceID.DataSource = New BindingSource(dictIDs, Nothing)
  3.  cboSourceID.DisplayMember = "Value"
  4.  cboSourceID.ValueMember = "Key"
  5.  
Dec 14 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: ASP Yaboh | last post by:
I have a WinForm ComboBox that is populated by binding to a dataset that contains a list of employees (two columns: 1. employee id, 2. employee name). The id is bound to the ValueMember, the name...
2
by: farseer | last post by:
Hi, I have a combobox who's data source i set to an array of objects (call it MyObject). these objects have get properties: key, value, descr. i set ValueMember to "key", DisplayMember to...
2
by: Alpha | last post by:
How do I change the selected item in a listbox according to a Combox's selected item on the same form? The Combox is from a different table in the same dataset as the Listbox uses. Combox's...
1
by: John | last post by:
With the TreeView, when you have a node selected but the control is not focussed, is there a way to make the control show which node is selected? -- "I have nothing but the greatest respect...
2
by: Brett Romero | last post by:
After I remove all items from a combobox, the last selected item remains in the display area. I've tried: mycbox.SelectedText = string.Empty; and mycbox.refresh(); How do I clear the...
6
by: Smokey Grindle | last post by:
Say I have a combo box with the following simple object Public class MyObject public ID as integer public Name as string public overrides sub ToString() as string return name end sub end...
2
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a...
1
by: sbandalli | last post by:
Hello, I have a Datagridview which has a combobox,and 2 textbox, The combobox is bound to a Datasource(Database Sql Server and the table name is Category) ,and Datagridview is not bounded to any...
1
by: starlight849 | last post by:
Hello, I am writing a program that is connection to an oracle database using the tableadapter method. I am populating a drop down list with a distinct set of values. I am then wanting to display...
0
by: yousof | last post by:
i have web page that contian combobox filled from table If CtvAct.GetRecords("Fill_ActivityTb") = True Then AcivityCombo.DataSource =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.