I have a list box that contains the ID number and model of a number of cars, taken from an access table. I have some text boxes that will be filled with the data from that table when a car is selected from the list box. To get the id number of the selected car, I'm using this code:
int idNum = listBox1.SelectedItem.ToString()[0];
Which should get the first character in the item string (it's ID number). When I select the first item in the list, what I am instead getting is 49. My first thought was that I wasn't casting it to an int, so maybe the 49 represents some character code for the number, however
Convert.ToInt16(listBox1.SelectedItem.ToString()[0])
Returns the exact same number. The second item is 50, and so on and so forth.
I want to be changing how I get the ID number from this char conversion anyway, as it's just occurred to me that once I hit 10 cars it won't work, but why am I getting such a large, consistently offset, and (perhaps most bafflingly of all) multi-digit number from a c# equivalent of java's charAt[0]
?
The specific error I've been getting is that there is no row at position 49
, which pops up when I try to get the value of mydataset.Tables["mytable"].Rows[idNum]["CarID"].ToString();
. Now, I can see a few things that could be causing this issue, I have absolutely know idea if Rows[idNum]["CarID"]
is the correct syntax, and was very surprised to see that my guess worked, but it's still a very weird problem.