Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Override Click on a control? 1

Status
Not open for further replies.

rdgerken

Technical User
Jul 8, 2002
108
I have an application that uses the compact framework. I have a listbox that I want the user to be able to multi-select items in this listbox. I added some code I found to enable this functionality, and it works great. On the emulator, I can CTRL-Click different items in the list box to select and deselect them. However, when I deploy the application to my device, it seems as if when I hit the CTRL key, it is stored in a keyboard buffer, it is not sent along with clicks on the screen with the stylus. In other words, I can tediously multi-select items in the listbox using the keyboard, but I can not get this device to do a "CTRL - Click" using the stylus. Can anyone provide some sample code that will "override" the clicks to the listbox... so that instead of sending a left mouse button, I always send a left mouse button with a control key modifier? Please note, I only want to do this for clicks on the listbox, not any of the other controls on the form. One other note, if I use the built in, on-screen keyboard, it of course works fine - however, I really can't have the operator using this keyboard. Thanks!
 
I believe ListBox.SelectedItems isn't supported by the compact framework. This makes it very difficult to do what you ask.

I've never used the compact framework before.. are you even able to support multiple items in your code? Or can you only access the SelectedItem property?

If this wasn't the compact framework, I would override the mouse-down event and add the item under the cursor to the SelectedItems collection using IndexAtPoint() method (or remove it if already in the collection).

I'm not sure you can even do that in this situation though.
Hope this provides a little insight though.
 
CrashDome, thanks for the response.

My apologies, I actually used a listview, not a listbox... don't know how much of your response this will change.

I wanted to do something like that, however, I'm finding that I'm having trouble finding what the item is under the cursor. It seems that there is a FocusedItem, but it doesn't seem to be updated until after the SelectedIndexChanged event.

I really would like to know how I can send a Ctrl left click instead of a left click to the control. That would be the best.

Overriding the mouse down event is a good idea, I just need to be able to find out what the item under the cursor is!

Thanks again
 
Actually, ListView is just as easy. I do it all the time.

private void ListView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
ListView lv = (ListView)sender;

ListViewItem itemUnderMouse = lv.GetItemAt(e.X,e.Y);
if (itemUnderMouse != null)
{
itemUnderMouse.Selected = !(itemUnderMouse.Selected);
}

}
 
Extra Note: You do not need to send a Ctrl-Click in this case. This is merely an override that will select/deselect no matter what kind of click is performed (Rt Click, Left Click, Middle-Click, etc...)
 
CrashDome

You were right on with your suggestion, however it doesn't seem that GetItemAt is supported by the compact framework. :( Any other suggestions?
 
I am certainly not very familiar with the compact framework, but perhaps you are stuck. Another option may be to purchase a third-party control?

Sorry my suggestion did not work out for you!
 
Well, I finally found a solution that worked for me, and that was to go ahead and use the checkboxes. (I didn't go this route originally because of another issue I had, but I got it worked out). Thanks again for all of your help. I will be sure to use your tip on non-compact framework applications. ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top