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
Related
I would like that when I click the combobox to see all the items that I can select, before show the items, serach in the database the items that it has to show.
But I don't do that when I click the item that I want to choose, that it good be the event selectedItem.
But I am not sure which is the event when I click the combobox to see all the items.
I am using MVVM Light.
Thanks.
This is DropDownOpened: https://learn.microsoft.com/pl-pl/dotnet/api/system.windows.controls.combobox.dropdownopened?view=netframework-4.8
But I think you should consider doing it in a different manner.
When user clicks combobox to show its items, he expect that the items... will be shown :) But you are going to load them.
I suppose you use some kind of filtering data, and when user clicks the combobox, then proper data gets loaded. I would consider loading them on changing the filter. I think that loading data on combobox click is too late.
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.
Apologies for not posting any code for this but all my efforts seem to be going nowhere.
I need to get the name of an observableCollection a textblock is bound to from the mouseDown event handler, so I can then perform some operations on the data, is there any way to do this?
I have set the Tag of the textblock to {binding} so i get the entire object back the textblock is bound to. Other than this im not sure where to go next.
Update:
The reason for this is that I have 2 multiselect treeviews, with a heirarchial data template, each template shares the same treeview but is bound to a different observable collection.
The way my multiselect works is by applying a style to each treeview if the IsSelected value of that item in my collection is true.
Now I am using the Mousedown event handler for the textblock in my datatemplate to get the item I am working on, BUT some items can be in both collections at once. I need to know which item to set the IsSelected value on. Using Binding{tag} I get the Item I need to set on but not the collection it is within.
I'm using Mousedown as the event handler because If you click on one item to select it, then click again it needs to unselect and the treeview event handlers didnt seem to allow this to happen (SelectedItemChanged etc).
As a side note I also need to be able to hide the default selected style of the Treeview as this isnt used and it gets confusing.
You can't determine what collection an item is in, but you can determine what TreeView the user clicked on. Then you can get the collection by knowing the TreeView, which should solve your immediate problem.
In my C# app, I have a ListView on a Form. I want the user to be able to double-click on a section of the ListView when no items are selected in order to pop up a "New Item" dialog. The problem is that the DoubleClick event for the ListView only fires if an item is selected.
Is there a way to do this?
There is a way to do this, but you have to do some low-level drilling into the Windows machinery. It's generally not a good idea to spend a great deal of time trying to get a standard Windows control to behave in a non-standard manner.
A simpler way is to just put a "New Item" button next to your ListView. If screen real estate is an issue, you could just add an extra row at the bottom that says "{click here to add new item}", and show your dialog when the user clicks this last row.
Add an event handler for the List view's MouseDoubleClick event.
Assuming Windows Forms:
Perhaps a good workaround would be to use a ContextMenu.