1
Answer

problem with listview

suhardie ahmad

suhardie ahmad

16y
1.9k
1
hello there...
im new in c#...

i was using listview in my development...
i need to user can select any item in the listview..
for your information, below is my code;

public list() {
listView1.View = View.Details;
listView1.Columns.Add("itemA", 200, HorizontalAlignment.Left);
listView1.Columns.Add("itemB", 200, HorizontalAlignment.Left);

// Add items
ListViewItem[] item = new ListViewItem[99];
item[0] = new ListViewItem("NO1");
item[0].SubItems.Add("NO1.A");

ListViewItem[] item = new ListViewItem[99];
item[1] = new ListViewItem("NO2");
item[1].SubItems.Add("NO2.A");

ListViewItem[] item = new ListViewItem[99];
item[2] = new ListViewItem("NO3");
item[2].SubItems.Add("NO3.A");

// Add the items to the ListView.
listView1.Items.Insert(0, item[0]);
listView1.Items.Insert(1, item[1]);
listView1.Items.Insert(2, item[2]);



}

// when select by user
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
listView1.FocusedItem.Selected = true;
textbox1.text = listView1.FocusedItem.Text;
}


the problem is, the first time click it ok, but i got problem when user want to click another item in the list. i need to deselect the first item and select the new item click by user and get the index. which part i can fix it?
Answers (1)