469,627 Members | 938 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,627 developers. It's quick & easy.

ListViewItem.Selected and SelectedIndexChanged

LV
Hello,

I would like to manually set one of my list view items as selected. When this item is set, I would like for a method to execute. I have a delegate on the list view for SelectedIndexChanged. For some reason, when I set the listviewitem.Selected = true, the event is not fired. Here is my code:

using System;
using System.Windows.Forms;

namespace DOMBuilder.GUI
{
public delegate void SelectedDomainObjectChangedHandler();

public class DomainObjectModelListView
{
public DomainObjectModelListView()
{
list.SelectedIndexChanged +=
new EventHandler(SelectedIndexChanged);

list.Items.Add(new ListViewItem("Item1"));
list.Items.Add(new ListViewItem("Item2"));
list.Items.Add(new ListViewItem("Item3"));
}

protected virtual void SelectedIndexChanged(object sender, EventArgs e)
{
Console.WriteLine("In SelectedIndexChanged");
}

public void SelectItem(int i)
{
// SelectedIndexChanged should fire after this call
list.Items[i].Selected = true;
}

private ListView list = new ListView();

static void Main()
{
DomainObjectModelListView listView = new DomainObjectModelListView();
listView.SelectItem(0);
}
}
}
Jul 21 '05 #1
0 1628

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Kluch | last post: by
1 post views Thread by Aaron Prohaska | last post: by
12 posts views Thread by moondaddy | last post: by
reply views Thread by Graham | last post: by
11 posts views Thread by Santosh | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.