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.
Related
I'm new to the C# part of programming, I am currently making a Program that is centered functionally around a ComboBox. In the Combobox, I have a concatenated string that looks like this:
IF checked
("☑ " + client.shortName)
IF unchecked
("☐ " + client.shortName)
So the output would be something like
☐ RealMadrid
As one item in the dropdown list of a comboBox.
My question is, can I implement an event handler that detects when the CheckBox (Not the actual Control Type, more like a character) region of the dropdown is clicked? If yes, Can I get a walk-through on how to do it? (It doesn't have to be a full class, but I would be grateful if It was)
Thanks
Wouldn't you be able to use the SelectedIndexChanged event, then just check the first character of the selected value (string) for '☑' or '☐'?
Edit - I think I understand - you want the user to be able to select the item without changing the checkbox 'checked' property, but also allow them to change it if they click towards the left side of the item. You can check the location of the cursor in relation to the form location and determine which side of the combobox they are selecting. It is not necessarily a clean implementation, but I don't think there's another way to fool the program using controls like that.
Is there a specific reason to be using a ComboBox as opposed to a number of Checkboxes where the text is updated with the client.shortName?
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.
I have a CheckedListBox in my Windows forms application, but items can be added that are to wide for the control to display. Is there any way to have the text wrap to the next line when this occurs?
I know with a standard ListBox this would not work, since it would be hard to tell the difference between the second line of one item and the next item. But with a CheckedListBox the beginning of the items in the list are defined by the CheckBox, so it should be easy to differentiate between items.
Is this possible? Will I have to create my own control (Again)?
The CheckedListBox does not support this, but you can use a DataGridView with two columns (checkbox column, text column) to achieve this with very little effort.
I'm having issues using a GridView as a ListView's View, what I want to do is fire an event when a user makes a selection from a combobox within the Gridview and pass the selected item within the event.
My first issue is that when the user clicks the combobox within a row, the row isnt selected (meaning the selecteditem stays null unless they click elsewhere first). Is there a clean way to do this without trying to catch mouse clicks or anything?
Secondly theres no selectionchangecommited event on a WPF combobox, is there a cleaner way to check if a user has manually selected an option other than checking if the combobox is enabled?
Thanks
I am seeing a similar behavior. My hypothesis is that one or more layers of the DataTemplate of each item in the list is swallowing the RoutedEvent that should have resulted in a new selection. Is it possible to, in a generic way, tell the items in the DataTemplate that they should never stop the event from bubbeling or tunneling further, without having to override every focus-triggering event handler in code behind?
I 'solved' my issue by using the WPF Toolkit grid (http://wpf.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=29117) and a series of selected items, which is probably a cleaner solution anyway.
Doesn't explain the behavior of the GridView, which is to me unusual
Original link has died, believe this to be the one https://github.com/xceedsoftware/wpftoolkit/wiki/DataGrid
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