473,404 Members | 2,179 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,404 software developers and data experts.

ListView VS TreeView

Hello,

Can ListView have some event just like the event BeforeSelect of
TreeView?
When a user try to select another item in the ListView, I would like to
do some checking first. If the result is true, then prevent the current item
jump to another one. In TreeView, I can set e.Cancel = true in the event
BeforeSelect. However, can I do similar thing in ListView?
Thanks.
Nov 15 '05 #1
4 5515

Hi alan,

Thanks for posting in this group.
As a workaround, I think you can override listview's OnSelectedIndexChanged
method, then you can do your customize selection and de-selection.
For example, you do like this:

protected override void OnSelectedIndexChanged(EventArgs e)
{
//de-select all the original selected items
for(int i=0;i<this.SelectedItems.Count;i++)
{
Console.WriteLine("SelectedItems:{0}",this.Selecte dItems[i].Text);
this.SelectedItems[i].Selected=false;
}
//select the first item.
this.Items[0].Selected=true;
return;
}

It works well on my machine, hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #2
Thanks for your reply first.
However, if I try to change the selected value of any item in the
OnSelectedIndexChanged, it will fire the event again which will continue
looping.

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:XI**************@cpmsftngxa07.phx.gbl...

Hi alan,

Thanks for posting in this group.
As a workaround, I think you can override listview's OnSelectedIndexChanged method, then you can do your customize selection and de-selection.
For example, you do like this:

protected override void OnSelectedIndexChanged(EventArgs e)
{
//de-select all the original selected items
for(int i=0;i<this.SelectedItems.Count;i++)
{
Console.WriteLine("SelectedItems:{0}",this.Selecte dItems[i].Text);
this.SelectedItems[i].Selected=false;
}
//select the first item.
this.Items[0].Selected=true;
return;
}

It works well on my machine, hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #3
How about setting a flag and checking for the flag before changing the
selection?

Like,

protected override void OnSelectedIndexChanged(EventArgs e)
{
// internalTrigger is a bool flag
if (internalTrigger)
return;

internalTrigger= true;

//de-select all the original selected items
for(int i=0;i<this.SelectedItems.Count;i++)
{
Console.WriteLine("SelectedItems:{0}",this.Selecte dItems[i].Text);
this.SelectedItems[i].Selected=false;
}
//select the first item.
this.Items[0].Selected=true;

internalTrigger = false;
return;
}

"alan" <ab*@hotmail.com> wrote in message
news:Ox**************@TK2MSFTNGP09.phx.gbl...
Thanks for your reply first.
However, if I try to change the selected value of any item in the
OnSelectedIndexChanged, it will fire the event again which will continue
looping.

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:XI**************@cpmsftngxa07.phx.gbl...

Hi alan,

Thanks for posting in this group.
As a workaround, I think you can override listview's

OnSelectedIndexChanged
method, then you can do your customize selection and de-selection.
For example, you do like this:

protected override void OnSelectedIndexChanged(EventArgs e)
{
//de-select all the original selected items
for(int i=0;i<this.SelectedItems.Count;i++)
{
Console.WriteLine("SelectedItems:{0}",this.Selecte dItems[i].Text);
this.SelectedItems[i].Selected=false;
}
//select the first item.
this.Items[0].Selected=true;
return;
}

It works well on my machine, hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Nov 15 '05 #4

Yes, a flag can greatly decrease the unwanted loop call(On my machine, it
decreases from 30 to 3 times).
For multi-threading safety, I think you need to use Interlocked class to
mutex the flag's change.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #5

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

Similar topics

1
by: (Pete Cresswell) | last post by:
TabControl on the right side of a form with two tabs: Tab #1 contains two subforms that show some dynamic query results. Tab #2 contains a ListView that gets dynamically populated as the user...
1
by: newbie | last post by:
Hello, I maybe asking too much in a single posting, but here it goes: I building a windows form that mimic's the Outlook XP GUI. Its a three pane form that will allow a user to view and edit...
2
by: Adam Klobukowski | last post by:
Hello i need to find out the last fully visible item of a Llistview. If it would be a treeview then it would be easy, I'm even thinkin of faking my treeview as listview, but maybe there is some...
3
by: Danny Tuppeny | last post by:
Hi all, I need to build a Treeview/Listview control (none of those on codeproject do quite what I need!), and was considering using one of the existing controls as a starting point, though now...
7
by: Progalex | last post by:
Hi everybody! I have a listview and a treeview in a form . With an OpenDialog I let the user select multiple files and then these files are added to the listview with the complete pathname,...
0
by: Danny Tuppeny | last post by:
Hi all, I have a need to display a message list in the same way as Outlook Express/Thunderbird displays new posts (and probably most other newsreaders, like the one you're using now!). I know...
6
by: Beginner | last post by:
Hi, I'm trying to populate a TreeView from an existing and filled in ListView (lvwBuild). lvwBuild is a basic two column listview which can have any number of rows. I would like the first...
0
by: MrColeyted | last post by:
I am designing an app that is similar to Windows Explorer. I have all working well. By clicking a directory in the treeview, the folders and files for that directory are displayed in the listview....
1
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i am looking for a way to clear and fill a listview and right after a treeview nearly flicker and delay free. The TreeView and Listview contain Images and about 1000 Items. What can someone...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.