Is there a way to get the clicked ListView cell when a user clicks somewhere inside the ListView?
I can get the current ListViewItem by SelectedItems[0] but I don't know which SubItem is clicked.
SubItems don't have events on their own type.
You can use the ListViewItem.GetSubItemAt Method to determine what sub item is under the mouse (if any).
ListView.SelectedIndices may help (.net 1.1>)
Related
I'm trying to make an application where I have this combobox that automatically opens and closes on mouse enter and mouse leave events respectively and then gets the value of the combobox before i leave it.
I already have the dropdown behavior as given by someone who posted it online. But now I need to get the value of my combobox item without clicking the mouse. I've tried selectedvalue or selecteditem but all seems to require mouse clicking. Is there any way of getting the value of the combobox where the mouse points to before I leave/close the combobox?
You can use labels for the combobox items.
Add 'MouseMove' event and in the event take the label text.
Here is an example how to implement very closely connected behavior: ComboBox MouseLeave MouseEnter.
I am trying to look for a simple way to design a winform with a combobox that has checkbox values in it to select multiple values.
But there are no free samples I could find.
If anybody has a good link for a sample which does not require a license.
Please let me know.
I am not looking for controls like telerik and infragistics.
Maybe this example can help you.
CheckBox ComboBox Extending the ComboBox Class and Its Items
It sounds like what you really want is a checked listbox control or maybe even just a listbox. These controls do multi-select in a way that is more standard for Windows.
If you really need a combo box with checkboxes in it, here's an article on code project I used once.
My suggestion, if space is an issue as #rmc00 has eluded to, place a button at the end of a readonly Textbox with perhaps an elipse (...) or down arrow (same as combobox) as the text of the button and when clicked or MouseDown make visible and position a CheckBoxList or open a popup dialog with a CheckBoxList this way you can either prepopulate at design time or pass a DataTable as a parameter/property to your control/form so it is databound at runtime. You can always place your control or write code to position the control/form exactly below your TextBox in the MouseDown/Click event. On check change update your textbox with a comma separated list (or go fancy and say if more than 3 items the text box can have the list stored in the Tag and the TextBox Text can have the count of items checked). Finally on LostFocus hide the Control (or Form), and further if you want to get fancy make the exception to not hide when the ActiveControl is the Button that way you can toggle the visibility of consecutive button presses.
Am having a list box item template, using wrap panel in container to show as three column listbox. working well. now the issue is, i have to capture the selection change only when user clicks on the second column.
is it possible to set the selection area in listbox?
I don't think it is possible to somehow raise selection change event only when the second or third column is selected. One thing you can do is keep last selected column index in a variable and inside your selection change event judge whether the new selected item belongs to same column or not if it doesn't simply ignore the change
I agree with Haris, I don't think it it possible. You should be able to use the mouse down event and then in code figure out the selection index from that. You could possibly use LINQ on the list box's ItemSource and find the match or use the Tag property of the item.
i'm trying to keep the last pressed item highlighted in the listview, anyone know how can i do it?
I'm assuming you want to keep the selected item highlighted when the control loses focus.
Then you should check out the HideSelection property.
You can subscribe to the SelectedIndexChanged event and change the selected index/item to the last one.
Looks like you can use ListView::DrawItem for that. Have a look here for an example.
Try looking at the code example here: List view Highlight selected.
It shows how to set the foreground/background color of the listview selected item when you change focus away from the listview control.
Pretty straight forward question, but I can't find a way to do it.
When a user double clicks an item in my ListView I want to save the index number of the clicked item.
Assuming that you have a reference to the ListViewItem:
listView.Items.IndexOf(listViewItem)
Or just access listView.SelectedIndices in the Activate event handler -- if your ListView is single-select then there'll be only one index in there.
It depends on which ListView you're using. All three have a property to get the selected item's index:
For Windows Forms, use ListView.SelectedIndices
For WPF, use ListView.SelectedIndex
For Web, use ListView.SelectedIndex