Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Keeping Index of Data when loading Data into ComboBox

$
0
0

I am Filling a ComboBox from a SQL-Server Table but as the Data is sorted I am losing the original Index.

For instance, if I have 3 entries in my Table as follows ...

IDDATA

0Z

1Y

2X

and I Fill my ComboBox with the DATA, then when I select X the SelectedIndex will be 2, which is the correct key from the SQL-Server Table it is loaded from.

However, if I Sort the Data using the ORDER BY command in my SQL statement, the Data will display in the ComboBox as ...  

X

Y

Z

... and if I select X the SelectedIndex will be 0 because that is the Index within the ComboBox, not the SQL Index / key.

How do I display the ComboBox in Alphabetical Order but also store, or remember, the original SQL Index ?

I guess this is pretty basic, but I seem to be going round in circles !!!


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>