protected void pnlFriends_Click(object sender, EventArgs e)
{
ClickablePanel pnlFriends = sender as ClickablePanel;
lvFriends.SelectedIndex = ((ListViewItem)pnlFriends.Parent).DisplayIndex;
}
Does not hit the following:
protected void lvFriends_SelectedIndexChanging(object sender,
ListViewSelectEventArgs e)
{
GetConversation(lvFriends.DataKeys[e.NewSelectedIndex][0].ToString());
}
How come? I used to get this working with WinForms using .Selected = true; However, it looks like there is absolutely no way to dynamically fire the ListViewSelectedIndexChanging event.
Any ideas how can I get this to work properly? Thank you.
EDIT
I am trying to select a ListView Item, and when the index changes. I am trying to populate a second ListView on the same page. I need to handle the first event when the index changes.
UPDATE (RESOLVED)
protected void lvFriends_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
{
lvFriends.SelectedIndex = e.NewSelectedIndex;
lvFriends.DataSource = Friendship.GetFriends(User.Identity.Name, false);
lvFriends.DataBind();
GetConversation(lvFriends.DataKeys[e.NewSelectedIndex][0].ToString());
}
protected void pnlFriends_Click(object sender, EventArgs e)
{
ClickablePanel pnlFriends = sender as ClickablePanel;
lvFriends.SelectItem(((ListViewItem)pnlFriends.Parent).DisplayIndex);
}
^ Works flawlessly.
I guess somehow, .SelectItem triggers ListViewSelectEventArgs and we would have to handle it by setting .SelectedIndex = e.NewSelectedIndex; and then rebinding the data to display the selected item properly.
Now what I can do with the code above is just call this -> lvFriends.SelectItem(int);
Also, please check the original question! 😉