473,386 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1831

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fritz | last post by:
I know it, I know it. It's come up a lot. I've done the Googling, but the standard answer doesn't do what I expect it to. For the record, the standard answer is: "Set the Selected property of a...
0
by: Kluch | last post by:
I am trying to select and focus single ListViewItem and can't seem to do so, here is my code: IEnumerator * itemList = mLsvMyList->Items->GetEnumerator(); while (itemList->MoveNext()) {...
1
by: Aaron Prohaska | last post by:
I'm having the problem with this drop down list on postback. For some reason both the ListItems get selected when I change the selected item. Using the code below I'm building the drop down list in...
12
by: moondaddy | last post by:
I have a dropdown combo box on a form and I have its AutoPostBack property set to true. When I select something from the list it does a postback and then the Page_Load event fires followed by it's...
5
by: Patrick.O.Ige | last post by:
I'm binding a CheckBoxlist below in the ItemDataBound(the CheckBoxList is in a Datalist) By doing "li.Selected = True" i can see all the checkBoxes are selected. But what i want is to be able...
0
by: Graham | last post by:
Hi everyone I have a form which contains a ListView control. The code handles the SelectedIndexChanged event, and changes some icons on some items in the ListView. I've found that when I...
1
by: LagartijaNick | last post by:
Question: I have a ListView in which I'm selecting a ListViewItem based on the value of a textbox. On my XP machine (with default color scheme) the ..Selected row is a noticable grey (back color...
0
by: LV | last post by:
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....
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.