Custom/named indexes for a Listbox?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aktor
    New Member
    • Jul 2009
    • 2

    Custom/named indexes for a Listbox?

    Hi,

    Let me start from the beginning...

    I'm using a custom database class to access data in a MySQL database (using the MySQL connector). As you will see below, the DBControl.Selec tQuery method returns a dictionary with the column names as keys, and each key's value contains a List<string> of the fields under that column.

    I'm loading these values into a ListBox as follows:

    Dictionary<stri ng, List<string>> queryResult = DBControl.Selec tQuery("SELECT pkiOperatorID, sOperatorName FROM tOperators");

    for (int i = 0; i < queryResult["pkiOperato rID"].Count; i++)
    {
    listBoxOperator s.Items.Add(que ryResult["sOperatorN ame"][i]);
    }

    So, the Listbox now contains all the values of the sOperatorName column in the table. That's fine and good, but how do you reference the primary key now? If I have to make a change to the record (for instance, clicking on the name in the ListBox, having it then appear in an InputBox and changing the name there), I obviously have to do an UPDATE sql query. But to do that, I need to be able to know which pkiOperatorID that sOperatorName goes with.

    So basically - how can I retain that relationship between the 2 values? (or the key and value, if you will)

    Any help would be greatly appreciated!
  • IanWright
    New Member
    • Jan 2008
    • 179

    #2
    Ok, I've only read a few sentences so not got the full post context. But it sounds like you want to bind a Dictionary to a ListBox and change the DisplayMember property so that the things it displays are the values in the Dictionary?

    Look at the ListBox.DataSou rce and ListBox.Display Member/ListBox.ValueMe mber properties if thats the case.

    Comment

    Working...