HI,
Am getting an error on this line ; it says input string was not incorrect format please help...
int userid = Convert.ToInt32(Selected_List.SelectedItems[0].SubItems[0].Text.ToString());
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Selva GanapathyPosted Dec 3, 2014, 12:49 AM
Hi Enos,
You can use either intTryParse or Int16Converter class to achieve this
if(new Int16Converter().IsValid(Selected_List.SelectedItems[0].SubItems[0].Text.ToString()))
{
int userid = Convert.ToInt32(Selected_List.SelectedItems[0].SubItems[0].Text.ToString()
}
else
{
// Message
}
Regards,
Selva Ganapathy K
VulpesPosted Dec 2, 2014, 10:01 AM
int userid;
bool isValid = int.TryParse(Selected_List.SelectedItems[0].SubItems[0].Text, out userid);
if (isValid)
{
_imageId = userid;
}
else
{
// perhaps issue some warning to user
}
Michal HabalcikPosted Dec 2, 2014, 4:44 AM
Try to check what are you actually trying to parse:
Console.WriteLine(Selected_List.SelectedItems[0].SubItems[0].Text)
EnosPosted Dec 2, 2014, 4:42 AM
_imageId = userid;
Use of unassigned local variable 'userid'
vaibhav bhargavPosted Dec 2, 2014, 4:34 AM
Check what you are getting for Selected_List.SelectedItems[0].SubItems[0].Text.
It may contain something that can not be INT,further
Text property itself of type 'string',.Tostring() is not required so change
Convert.ToInt32(Selected_List.SelectedItems[0].SubItems[0].Text.ToString());
to
Convert.ToInt32(Selected_List.SelectedItems[0].SubItems[0].Text);
Michal HabalcikPosted Dec 2, 2014, 4:25 AM
int result = int.MinValue;
int userid;
int.TryParse(Selected_List.SelectedItems[0].SubItems[0].Text, out result);
if (result != int.MinValue)
userid = result;
Manish Kumar ChoudharyPosted Dec 2, 2014, 4:17 AM
it means that Selected_List.SelectedItems[0].SubItems[0].Text does not contains a value that can be converted to int.
so user