Note that there are some explanatory texts on larger screens.

plurals
  1. POListview selected item value - not Index
    primarykey
    data
    text
    <p>I am working on a project (simple phone book) for personal use. <a href="http://s24.postimg.org/4eprhylpx/screenshot_53.png" rel="nofollow">This is how it looks like</a>:</p> <p>I have a listview filled with contacts and everything was working perfectly untill I added this line of code, when everything became messed up.</p> <pre><code>listView1.Sorting = SortOrder.Ascending; </code></pre> <p>So, the problem is obvious. Let's say that there are 6 contacts in the list, and <strong>Contact 1</strong> lives in <strong>City 1</strong>, on <strong>Address 1</strong>, has a <strong>Tel. No 1</strong> [etc], and <strong>Contact 2</strong> lives in <strong>City 2</strong>, on <strong>Address 2</strong>, has a <strong>Tel. No 2</strong> etc. [...sequence continues...]</p> <p>When I try to make some changes, for example, <strong>Contact 5</strong> suddenly gets the information of other contact, in this case, <strong>Contact 7</strong>. It doesn't matter whose information it gets though, the matter is that everything becomes messed up. </p> <p>Also, if i want to delete all the contacts from the listview - it is not possible - there will always be one remaining. For example, if there were 6 of them, 5 would be deleted and there would be one left. Also, if there was 100 of them, it would delete 99 and the one would always remain as well. </p> <p>I figured out that there is no sense to use index of selected item anymore and that I have to use value of the selected item now (instead of its index). But, the problem is I do not know how to do that. </p> <p>Maybe it comes to listView1_SelectedIndexChanged only. Please note that i am just taking a guess, I am not completely sure. </p> <p>If so, here is the code: </p> <pre><code>private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (listView1.SelectedItems.Count == 0) return; textBox1.Text = people[listView1.SelectedItems[0].Index].Name; textBox2.Text = people[listView1.SelectedItems[0].Index].Hometown; textBox3.Text = people[listView1.SelectedItems[0].Index].Address; textBox4.Text = people[listView1.SelectedItems[0].Index].Phone; textBox5.Text = people[listView1.SelectedItems[0].Index].Email; textBox6.Text = people[listView1.SelectedItems[0].Index].AdditionalInfo; dateTimePicker1.Value = people[listView1.SelectedItems[0].Index].Birthday; textBox1.ReadOnly = true; textBox2.ReadOnly = true; textBox3.ReadOnly = true; textBox4.ReadOnly = true; textBox5.ReadOnly = true; textBox6.ReadOnly = true; dateTimePicker1.Enabled = false; toolStripButton5.Enabled = true; } </code></pre> <p>I think the code is to big to upload it here, so <a href="http://www.sendspace.com/file/ftuew8" rel="nofollow">I uploaded the code here</a>:</p> <p>Does anyone have a solution? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload