I've got a listview on a form in report style. It's populated with 40
item. I want to prevent the used clicking on some items, and if the
user clicks on one of these items I want the selection to revert back
to the old selection, hideselection property if false, listview is
single select.
In the OnSelectedChang e() handler I test to see if the newly selected
item is a selectable one, if it's not, I try to change the selection
like so.
private void OnSelectedItemC hanged(object sender, System.EventArg s e)
{
if( listView1.Selec tedItems.Count != 0 )
{
int idx = listView1.Selec tedItems[0].Index;
bool ret = execScript.isEx ecutable(idx);
if(ret == false)
{
listView1.Items[execScript.getC urrentExecNum()].Selected = true;
listView1.Selec t();
listView1.Ensur eVisible(execSc ript.getCurrent ExecNum());
listView1.Focus ();
}
}
This doesn't work.
Neither does posting a user message to this function by overriding the
WndProc and calling Win32
[DllImport("user 32.Dll")]
public static extern Int32 PostMessage(Int Ptr Handle, Int32
ConnectionType, IntPtr wParam, IntPtr lParam);
ResetSelection( )
{
listView1.Items[execScript.getC urrentExecNum()].Selected = true;
listView1.Selec t();
listView1.Ensur eVisible(execSc ript.getCurrent ExecNum());
listView1.Focus ();
}
Neither does using a delegate like this
listView1.Begin Invoke(new
OnSelectedItemC hangedDelegate( ResetSelection) ,null);
Neither does adding a filter on to the listview control and trapping
the LVN_ITEMCHANGIN G or LVN_ITEMCHANGED message in the WM_NOTIFY.
Interesting to note though if I add a button to the form and call my
ResetSelection( ) function it works fine.
Three days I've spent on this. Can anyone help?
Thanks
Youngie... 1 3073
Try this:
ListViewItem selectedItem = null;
private void listView1_Mouse Up(object sender, MouseEventArgs e)
{
ListViewItem item = listView1.GetIt emAt(e.X,e.Y);
if (item != null && item.Checked)
{
item.Selected = false;
if (selectedItem != null)
selectedItem.Se lected = true;
}
}
private void listView1_Mouse Down(object sender, MouseEventArgs e)
{
if (listView1.Sele ctedItems.Count == 1)
selectedItem = listView1.Selec tedItems[0];
else
selectedItem = null;
}
<yo*****@youngi e.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. . I've got a listview on a form in report style. It's populated with 40 item. I want to prevent the used clicking on some items, and if the user clicks on one of these items I want the selection to revert back to the old selection, hideselection property if false, listview is single select.
In the OnSelectedChang e() handler I test to see if the newly selected item is a selectable one, if it's not, I try to change the selection like so.
private void OnSelectedItemC hanged(object sender, System.EventArg s e) { if( listView1.Selec tedItems.Count != 0 ) { int idx = listView1.Selec tedItems[0].Index; bool ret = execScript.isEx ecutable(idx); if(ret == false) { listView1.Items[execScript.getC urrentExecNum()].Selected = true; listView1.Selec t(); listView1.Ensur eVisible(execSc ript.getCurrent ExecNum()); listView1.Focus (); } }
This doesn't work. Neither does posting a user message to this function by overriding the WndProc and calling Win32
[DllImport("user 32.Dll")] public static extern Int32 PostMessage(Int Ptr Handle, Int32 ConnectionType, IntPtr wParam, IntPtr lParam);
ResetSelection( ) { listView1.Items[execScript.getC urrentExecNum()].Selected = true; listView1.Selec t(); listView1.Ensur eVisible(execSc ript.getCurrent ExecNum()); listView1.Focus (); }
Neither does using a delegate like this
listView1.Begin Invoke(new OnSelectedItemC hangedDelegate( ResetSelection) ,null);
Neither does adding a filter on to the listview control and trapping the LVN_ITEMCHANGIN G or LVN_ITEMCHANGED message in the WM_NOTIFY.
Interesting to note though if I add a button to the form and call my ResetSelection( ) function it works fine.
Three days I've spent on this. Can anyone help?
Thanks
Youngie... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: InvisibleDuncan |
last post by:
I have a ListView that populates some fields whenever the user selects an item. However, if they change the data in the fields and then select a new item without saving, I want to display a message box that warns that their changes will be lost, and asks them to confirm whether to continue. Sounds simple
Unfortunately, the ListView's SelectedIndexChanged event cannot be cancelled, and it's actually called for each change in the selection. So,...
|
by: Vanessa |
last post by:
With this program I can do one selection,
but upon the second I get an error where
///////////////// is indicated. Please help.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
|
by: Aron Henning |
last post by:
I have a ListView that contains the subfoldes of a local drive.
Whan i click on a subfolder the listbox should display the subfolders of
this folder instead.
the funktion is as follows:
private void FolderList_SelectedIndexChanged(object sender, System.EventArgs
e)
{
try
|
by: GTi |
last post by:
I have a listview that with selected items.
But I want to "reselect" items after a refresh.
Each items have a uniqe value in the Tag object.
After a refresh some new items may be added or removed
so using item index is not possible.
To get the list of selected items I use:
ListView.SelectedListViewItemCollection selItems =
this.listView1.SelectedItems;
|
by: Brian Henry |
last post by:
Ok whats going on here... got a couple problems... this is relevant now to
this group since .NET 2.0 is finally RTM
1) draws really slow when making it a large form (resizing speed is jerky)
to a res from 100x100 to 1280x1024 once it gets above 500x500 it starts
jerking you can see the screen refreshing as it paints
2) sometimes the background selection when you select multiple items then
move the mouse around on the screen dissapear...
| |
by: Brandon McCombs |
last post by:
Hello,
I have a form that contains a listview on the left side and a column of
buttons on the right side. Only some of the buttons do I want enabled
all the time. The other buttons should be enabled only if something is
selected in the listview. That part specifically works but not very
well. It seems that I can only get the buttons to disable if I click off
the text of the items in the listview but still within about 10-20
pixels of...
|
by: Jure Bogataj |
last post by:
Hi all!
I have a problem (performance issue) with listview. I have implemented an
ItemSelectionChange on my listview and put some code in it (I build some
toolbar based on selection and update info in statusbar). When selecting one
item (clicking on listview) it works fast, without noticing. However if
selecting multiple items with SHIFT (approx. 500 items) or selecting with
mouse, for each item selected through all listview an event...
|
by: Tom Bean |
last post by:
I am trying to display a ContextMenuStrip when a user right-clicks on an
item in a ListView and have encountered a something that seems strange to
me.
When the ListView is initially populated, no items are selected. When the
first item is selected by clicking either the left or right button, the
SelectedIndexChanged event fires but not the MouseUp event. After the first
item is selected and another item clicked on, both the...
|
by: Brandon |
last post by:
HI all,
I am working on a WPF listview that get items through the XMLDataProvider
and making a listview with two actual columns and in both CellTemplete XAML
in a grid bind more than one snippet of the XML data to the cell. Now this
works fine no problem...
When I try to setup a IsSelected trigger I lose the default listview
selection UI and only the new look of the ListViewItem after the trigger
takes effect shows what Item is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |