retrieving listview values
-
hi! everyone!! I am using Windows application. I want to get single,single value from listview(contains two column) when I click a row. my 1st column name is 'code'and value is '123' and second column name 'desc' value 'good' If i click its return value but gives this type of value:
listview1:{123}
code sample:
private void listView1_Click(object sender, EventArgs e)
{
ListViewItem value1 = (ListViewItem)listView1.Items[0];
string val =Convert.ToString(value1);
}please guide me, thanx and regards
-
hi! everyone!! I am using Windows application. I want to get single,single value from listview(contains two column) when I click a row. my 1st column name is 'code'and value is '123' and second column name 'desc' value 'good' If i click its return value but gives this type of value:
listview1:{123}
code sample:
private void listView1_Click(object sender, EventArgs e)
{
ListViewItem value1 = (ListViewItem)listView1.Items[0];
string val =Convert.ToString(value1);
}please guide me, thanx and regards
-
ListViewItem item = listView1.Items[0]
string val = item.Text;
string desc = item.SubItems[0].Textthanx sir! but i get only code value not desc value. in desc value also contain the code value. I ask one more question. actually when i click one row its work properly. but when i click secong row it returns also previous value instead of current selected row. please guide me what can i do when i select different rows the selected rows returns value thans and best regards
-
thanx sir! but i get only code value not desc value. in desc value also contain the code value. I ask one more question. actually when i click one row its work properly. but when i click secong row it returns also previous value instead of current selected row. please guide me what can i do when i select different rows the selected rows returns value thans and best regards
Phil pointed you to another ListView property: SubItems, which is indexable. Did you read up on it? did you perform a little experiment? BTW: when you know a column isn't text (say a number), and you want its value, then don't use Convert or ToString(), just cast! :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
hi! everyone!! I am using Windows application. I want to get single,single value from listview(contains two column) when I click a row. my 1st column name is 'code'and value is '123' and second column name 'desc' value 'good' If i click its return value but gives this type of value:
listview1:{123}
code sample:
private void listView1_Click(object sender, EventArgs e)
{
ListViewItem value1 = (ListViewItem)listView1.Items[0];
string val =Convert.ToString(value1);
}please guide me, thanx and regards
hey you can use given code to get value based on row on which you click.
// Given code will get value for 1st column
string txt = listView1.Items[listView1.FocusedItem.Index].SubItems[0].Text;if you need value of both second column you have to change value of SubItems to column index as
string txt1 = listView1.Items[listView1.FocusedItem.Index].SubItems[0].Text; // For 1st column
string txt2 = listView1.Items[listView1.FocusedItem.Index].SubItems[1].Text; // For 2nd columnyou can also use loop with SubItems for getting value.. :)
-
hey you can use given code to get value based on row on which you click.
// Given code will get value for 1st column
string txt = listView1.Items[listView1.FocusedItem.Index].SubItems[0].Text;if you need value of both second column you have to change value of SubItems to column index as
string txt1 = listView1.Items[listView1.FocusedItem.Index].SubItems[0].Text; // For 1st column
string txt2 = listView1.Items[listView1.FocusedItem.Index].SubItems[1].Text; // For 2nd columnyou can also use loop with SubItems for getting value.. :)
-
hi! everyone!! I am using Windows application. I want to get single,single value from listview(contains two column) when I click a row. my 1st column name is 'code'and value is '123' and second column name 'desc' value 'good' If i click its return value but gives this type of value:
listview1:{123}
code sample:
private void listView1_Click(object sender, EventArgs e)
{
ListViewItem value1 = (ListViewItem)listView1.Items[0];
string val =Convert.ToString(value1);
}please guide me, thanx and regards
Hi,, I have a Code in VB. Pls Convert this to c# using DeveloperFusion Website. textbox1.Text = trim(listview.SelectedItems(0).SubItems(1).Text) regards, Saran..t
-
Hi,, I have a Code in VB. Pls Convert this to c# using DeveloperFusion Website. textbox1.Text = trim(listview.SelectedItems(0).SubItems(1).Text) regards, Saran..t
saransaki08 wrote:
I have a Code in VB. Pls Convert this to c# using DeveloperFusion Website.
I am not getting it properly I think your question is not clear. will you elaborate it for better understand for me or others. :)