C# ListView items with custom controls - c#

I'm maintaining a C# application written with windows forms. I now need to have a list view where every item has a few custom controls.
Every item need to have title and a combobox. The problem is that the data for the custom boxes will be different. So for example Item 1 could have a ComboBox where you can pick 1-3. Item 2 would have a combo box where you can pick 1-2.
So in the property column I need a string, and in the value column a combobox, with different data sets for different items (or at least for different kinds of items)
I've been on this problem for a while, and I don't really know where to go from here.

Why don't you use a Property Grid control? It is composed by two columns, the left one being a fixed text for the key/title and the right one is dynamic, in the sense you can have comboboxes, textboxes, color selection controls, etc. for the value the user can input/select.

Related

WinRT XAML ComboBox opens in middle of list

So one particular behavior of the XAML combobox in WinRT is causing me a huge headache, because my client sees it as a defect, and doesn't care if it's the behavior of the control, he wants it changed. However, I cannot find anything that tells how to change it. The behavior I'm speaking of is that when nothing is selected the ComboBox popup opens displaying the ItemsSource in the middle of the list. I have a sorted list of countries, with the exception of US, UK, CAN being at the top. These 3 items are the most often selected items and the client wants them on top rather than having to scroll through the list to find them. That's easy enough, but because the list opens in the middle, you still have to scroll quite a bit to get to them. Is there some property I'm missing that turns this behavior off? I was able to finally convince them that the CarouselPanel wasn't a defect, but this one isn't going to fly.
Thanks in advance!
UPDATE:
So this combobox is databound through a ViewModel. in this instance, the ViewModel has no value (it is an empty string) for that particular property and so the Combobox shows empty, which is fine and desirable. When you click on the Combobox to select a value, it displays the list in the middle of the available values. this is the behavior that is undesirable. it should be showing the 1st value in the list at the top!
Well, one would think that the out of the box Combobox (there is no other built in dropdown control) would be able to work like any other combobox control in any other MS technology to date, but of course this is MS, so why should things be consistent. At any rate, I ended up having to create a "blank" entry and pre-select that item if the value in the VM is empty, and then write code in the setter of that property to ignore if "blank" item if it is selected. It's kludgy and wreaks of code smell, but it works
When you set the SelectedItem property to an object, the ComboBox attempts to make that object the currently selected one in the list. If the object is found in the list, it is displayed in the edit portion of the ComboBox and the SelectedIndex property is set to the corresponding index. If the object does not exist in the list, the SelectedIndex property is left at its current value.

WPF design & binding

I have a WPF application. I have a custom object that contain a list. The list is a custom type of "Order", the list contains 24 items. The list contains three properties. First property "baseCurrency" (i.e. GBP) of type string, second property "orderCurrency" (i.e. JPY) of type string & the third property "calculate" of type boolean.
In my WPF application I have a grid that is split into 24 equal size squares. In each square I want a control that contains a textbox and two small icon images. I want the textbox to be bound to the two string properties for an item from my list. The two small icon images are flags. So if we have GBP & JPY the two images would be their respective flags. I also want to bind the images based on the string provided. So if GBP is selects the gbp.jpn image in my project folder - not sure how I do this?
I'm think of using a toggle button as my control that will contain the textbox and images. I hoping to bind each button to a list item. The calculate property will be bound to the toggle button IsChecked property. If IsChecked is true I want my calculate property to be true.
Is there a better control that I should be using rather than a toggle button? Is there also a better way of trying to accomplish what I'm after?
Your situation is so common that the MVVM pattern is widely used in WPF for that purposes. To get started, you may read about:
MVVM - To build your application structure
Data Bindings in WPF - To bind your data to grid in a right way
Data templates for controls in WPF - To adjust the data bound
There is also a post on my blog related to working with currency in WPF application

Win8 Grid template how to hide all items from groupeditems page?

I'm new about win8 and developing visual studio.
I use Grid template and i wondering...
How to hide all items, but not Group name and group box.. I have too many items and i do want all item to this page. When click group box or title, find groupdetail page and there is all this group items?
Thanks.
The Grid template won't display all your items on the GroupedItemsPage. It uses the TopItems property in the view model to show at most 12 items. If you look in SampleDataSources.cs you'll see code (with a hard coded value - sigh) of 12 in ItemsCollectionChanged.
So, you could modify the 12 value if you want fewer, or if you want NO items to appear on the GroupedItemsPage, remove the GridView and perhaps replace it with a ListView whose ItemsSource is the group headers, but that's a bit more work and a change in the UI, which by all means is fine to do.
These templates are just a starting point, and we'd encourage you to make changes that make sense to provide the best user experience for your app.

With two comboboxes; How to load child item collections in second combobox based on the first combobox selected item

I'm working on a win project and I know this would be easy in WPF but I do not have the liberty to switch this project. I have to comboboxes, basically a Order ComboBox and an OrderItem ComboBox. I am using Entity Framework and I just wanted to find out what the best way would be to load the orderitems based on the order combobox selected order, i.e. each time an order is selected, the child combo must refresh its collection to the relevant selected order. I am using DevExpress as my control suite and would also love a DevExpress LookupEdit control example and also perhaps a way of doing this in the grid control's repository lookup edit. Please help>>>>
There is an example showing how this can be done at:
How to filter a second LookUp column based on a first LookUp column's value

In Winforms, can I configure the combobox to allow values not in the drop down list?

I have a combobox that displays a list of 'active' objects the user can select from. However, if the user goes into some older data screens, the selected values of some of the comboboxes might be old and 'inactive' objects that aren't in the current list.
I want the combobox to just display the old value even though it is not in the list. And I don't want the user to be able to manually edit it either.
Any suggestions?
Thanks!
Isaac
I would assume that it's your code that is removing the objects from the ComboBox in the first place, so you just... don't do that. To disallow typing into the ComboBox set its DropDownStyle property to ComboBoxStyle.DropDownList.

Categories

Resources