I'm displaying incomplete datasets in a listview.
When an item gets selected (doubleclicked or highlighted + enterKey),
I want to open a form, that allows me to add the missing data.
I checked the doc-page of ListViewItem and found that I should probably either use .OnSelected()-Method or .Selected-Event. However my IDE(#develop) offers neither of those, just a property called Selected Adding hte System.Windows.Controls-Namespace didn't change anything, though some googling suggested otherwise.
My question is:
How can I get access to these Methods/Events or is there a workaround, i.e. a ListView-Event that offers similar functionality?
Nevermind,
I used the ListView.ItemActivate-Event.
Related
I'm using the ObjectListView control from here.
I'd like to detect when a user right clicks the headers and hides or shows a column. Basically a ColumnVisibilityChanged event. The reason I want to detect this is to save the visible columns between sessions.
The ColumnWidthChanged event fires when this occurs (not on the column that has been removed), so I could iterate through AllColumns and check the value of IsVisible. However, that seems hacky and I'd like to avoid it. Also, that would get run several times when it didn't need to.
Anyone know of a better way of detecting a column being hidden or shown?
Well I found a solution that wasn't quite what I was looking for, but possibly better.
ObjectListView has SaveState() and RestoreState() methods as described here.
I began to make a program in c# using wpf and the mvvm pattern to learn this program language. I feel sorry that I finally have problems I can't solve using Google. But I try being precise.
At first I present you the GUI, so I can explain my problems more easily.
The xaml file of the MainWindow comes here.
As you see, it's not a serious and important program, I just made it to learn some techniques.
Now comes my main question:
I need the SelectedItem Property of the second ListView(Consumables) in the footer. I thought this wouldn't be a serious problem cause I can just bind it to the selected item using relative path and the name of the listview. This didn't work and caused a null reference error as soon as I added an item to this listview. I double checked the code and I am sure I haven't made something wrong there. So I thought the problem is, that it's kind of a descendant ui element.
My next try was to create a new property in my main view model which is bound to the selected item. You can find this in line 136. But as I found out, this causes me a System.NullReferenceException too if i click on an item. I think it's because this property is read only. I don't know what to do. Isn't there any other possibility to bind the SelectedItem as DataContext for the footer?
My Second Question is about line 27. The TabControl should always select the first Tab automatically. But it makes it only every second time. It's quite funny. If I scroll down the Champion Combo Box, the first tab goes: selected - unselected - selected - ...
My third and last Question is about 72 which is similar to line 50 (The DataContext is the same too) But the ICommand of the ContextMenu of the itemtemplate you see line 50 works, whereas the contextmenu (l. 72) does not call the Icommand. Weird.
It's a fun project, so I can provide you the source code if my information are not enough.
--Sorry, only two hyperlinks allowed--
Please help me. I am just a bit confused by this unsuspected behaviour. I haven't found anything that could help me and I'm sorry if the answers of these questions will be simple :P
Just to emphasize it: The main question is the only one I really need an answer for. The second one could be solved programatically. And to solve the third one, I could just remove this feature.
I'm happy for EVERY HINT!
Haven't gone through the entire question but you should bind selected item to your view model property (two way binding) and then bind another UIElement to this view model property (probably one way binding or check for value equality as to not cause stackoverflow exception)
I have a custom collection, lets says COL, that derives from ObjectModel.Collection.
I have my own collection editor that works fine when a property, of type COL, is Read and Write enabled.
However, if I change the property to ReadOnly, the open editor button stops showing in the property grid.
As a test, I override my custom editor with the CollectionEditor, and that worked fine.
So, my question is, what check is the property grid making, that CollectionEditor passes but my collection editor fails?
There's not much to override in UITypeEditor, so I fear there's some hard coding going on with regards to CollectionEditor.
Cheers.
ETA:
I've answered the question below.
I've found out why it wasn't appearing and it appears to be a bug in the PropertyGrid.
The button does appear if the EditStyle is set to Modal, but does not appear if it's set to DropDown.
One would have thought that the styles were just for ..., well, style?
Looking in reflector, the issue occurs because additional checks of readonly propertyies (such as checking if it's a reference type - and enabling the button) only happen if the style is set to modal. Hmmm, nice one.
I think the behavior you describe in your own answer is not a bug and is by design, and frankly it's quite logical. Look the dropdown editors around: they offer the user to make a selection and therefore the result is a new value for the property (see ColorEditor, AnchorEditor, DockEditor, CursorEditor, ...). As such the property must not be readonly. A modal editor is more to edit a value (usually a reference type) and therefore can be used even if the property is readonly. Of course, this one can also be used to select a new value (like the FileNameEditor for example).
So maybe the answer is "look at your UI design". Are you sure you should use a dropdown editor to edit the content of a reference type?
I'm hopefully missing something extremely obvious here, but for the life of me I can't figure this out.
I have an AutoCompleteBox control that is retrieving results by way of an asynchronous call, although I can't find a reliable way in which to know when a user has selected an option from the list of returned values. I've tried hooking into the SelectionChanged event, but that fires on every movement within the autocomplete's drop down list, when what I actually want to know is when a user has definitively said "Hey, that's the item I want!" by either clicking it, or selecting it with the return key.
Any advice would be greatly appreciated as this is starting to drive me a tad crazy now. =)
Thanks
P.S. The SelectionChanged event arguments provide AddedItems and RemovedItems, but don't give any direct indication of the type of selection I'm looking for.
There isn't a specific event that indicates that the used has specifically plumped for an option rather then merely browsing.
For you scenario the closest you can get is DropDownClosed or even LostFocus events then access the SelectedItem property.
If you are using the Telerik AutoCompleteBox, perhaps the "OnEntryAdded" event is what you are looking for. I see this question was asked over 4 years ago so perhaps this event didn't exist back then. I just updated to the latest update of Telerik controls (2014 Q2). Here's a quick example. I removed the properties that we're not discussing here to clean it up but, obviously, those will need to be added back in unless you're setting them in code (e.g. DataSourceID).
Source Page:
<telerik:RadAutoCompleteBox ID="RadAutoCompleteBox1" runat="server" OnEntryAdded="RadAutoCompleteBox1_EntryAdded" >
</telerik:RadAutoCompleteBox>
Test Code (in VB):
Protected Sub RadAutoCompleteBox1_EntryAdded(sender As Object, e As AutoCompleteEntryEventArgs)
MsgBox(e.Entry.Text) 'This is just to show you the DataValueField in your dev
MsgBox(e.Entry.Value) 'This is just to show you the DataTextField in your dev
racbCustomer.Entries.Clear() 'This will wipe out the selection(s)
End Sub
I have 2 questions concerning C#.
1) I have a dropdown menu with several items in them. They are clickable, but when I click one, the older clicked one stays selected. Click another and the 2 original ones stay selected, and so on. I don't want this. What I want is that when I click one of the dropdownitems, that one is that selected one and the others are not.
2) I have a listview items on a winform. I loaded some string elements into it from a file. Now what I want to do is to be able to edit those strings and even add strings, just by clicking on the rows in which the data goes.
I've checked google and MSDN for these problems, but nothing helps, so I turn here.
2) The ListView does not support that type of action. You can roll your own (pain in the #$$), or perhaps a DataGrid would be better suited to your purpose.
EDIT:
This link may help
This one too
For #1 I'm a little confused. If the DropDownStyle isn't set to simple something strange is occuring. It's not much but maybe you could try recreating the control.
For #2 the easiest solution I can think of is to set a TextBox to be equal to the selected text value from your listview. After that write a little function to update the selected index of the listview with the edited text from the listview.
Please comment if you have any more information about #1.