Shalem
Shalem

Reputation: 1516

Need to convert listview item of string type to long variable

I have a listview(lvwView1) of 8 columns and 3 rows. i need to convert the last subitem(7th item) in very first row(0th row) to long type. I tried multiple ways like:

long var= (long)Convert.ToDouble(lvwView1.Items[0].SubItems[7].Text);
long var = convert.toInt64(lvwView1.items[0].subitems[7].tostring());
long var = long.Parse(lvwView1.Items[0].SubItems[7].ToString());

Moving forward, i need to convert the last subitem(7th item) of Listview to long on subitem selected in listview (event - lvwView_SelectedIndexChanged).

Can Someone help in converting listview item of string type to long variable

Upvotes: 0

Views: 994

Answers (2)

Damith
Damith

Reputation: 63065

inside your event try below

long val = long.Parse(lvwView1.SelectedItems[0].SubItems[7].Text);

Upvotes: 0

Shalem
Shalem

Reputation: 1516

I found answer. The conversion specified below worked out for me

long lVal = (long)Convert.ToDouble(lvwView1.Items[0].SubItems[7].Text);

Upvotes: 1

Related Questions