0

Hi all fri,

Pls help me ; how can i solve this problem
" Cannot implicitly convert type 'System.Windows.Forms.ListViewItem' to 'int' "

I tried in so many ways but still can't.

i'm new in c# . i wanna get value from listview (it's view property is set in 'Detail')/multiselect is turn off.

Who wanna help me ?

Thanks in advance :) :) :)

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by __avd
0

Take a look at following code.

private void Form1_Load(object sender, EventArgs e)
        {
            listView1.Columns.Add("No");
            listView1.Columns.Add("Name");

            listView1.Items.Add(new ListViewItem(new string[]{"1","Mr.A"}));
            listView1.Items.Add(new ListViewItem(new string[] { "2", "Mr.B" }));
            listView1.MultiSelect = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count!=0)
            {
                int n = int.Parse(listView1.SelectedItems[0].Text);
                MessageBox.Show(n.ToString());
            }
        }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.