Cloning the WPF ComboBox control: Ideas or suggestions - c#

If have a control that acts like a record selector from a database, say, for example, customers.
The control must act in certain ways allowing the user to type the name, the alias or the code of the customer, and the control will select the correct one, or offer a list of possible candidates, and other behaviors.
I have tried to inherit from ComboBox, but there are some ComboBox behaviors that make it difficult or impossible to do what I want, so I'm better starting from scratch, with a TextBox and Button.
The questions are:
Do you know some open-source component so I don't have to start from zero?
Have you already done something like this and want to share methodologies or tips?
Am I good with a TextBox, a Button and a PopUp control?

Try this control from CodeProject: A Reusable WPF Autocomplete TextBox
It allows you to specify a source list, and a custom filter. In your custom filter you can select to show only those records that have a name, alias or code that fit the text entered, and the user will have a list of filtered options displayed to them.

Related

WPF Google-style ComboBox - AutoSuggestion

I want to have a Input field where I can input a string. That string could be a new item for that field or I choose to select an existing item. So I do not want Auto-Completion, but Auto-Suggestion which allows me to add entries to the ItemsSource by typing them in.
Basically it is like a normal WPF Combobox with
IsEditable="True"
But how can I get the ComboBox to reduce the list of suggestions to the string I input?
I don't want the ComboBox to present all Items of ItemsSource for selection, but only the ones that contain the string I input.
Can I do it due just setting some ComboBox properties?
For this propose you can use open source solutions like WPF AutoComplete TextBox control or other Autocomplete solutions
For this, I use the DevExpress library. If the ComboBoxEdit is configured correctly, it will auto display a drop down list which is continuously filtered by what the user types. Make sure you set the Mode to Contains, so it matches on any part of what the user types. Users love it as they can quickly narrow down the list of items to select from.
For the record, I am not affiliated with DevExpress. I'm sure Telerik has an equally good control as well.

Dynamically creating Tab+DataGrid for binding with multiple different classes?

I apologize for the crappy title, I wasn't quite sure how to summarize what I'm trying to do.
My scenario:
I am refactoring an existing WinForms application to WPF and MVVM. I'm currently working on a module that provides search functionality for a database comprised of many different tables such as Contact, User, Case, Product, etc. In code-behind there are classes which provide an Object for each. I have written wrapper classes for each of the searchable table Objects that expose only the properties a user would want/need to see in the search results for each type of Object, for binding to a DataGrid.
Once these search results exist, they need to be displayed in a combination of Tab Controls and Data Grids, like so:
Because of some use cases, I need to be able to create an individual display Tab+DataGrid for the results of every single search that is performed. I cannot have a single tab for each type of search that is shown/hidden as needed.
I'm not sure how to proceed from where I currently am to the goal pictured and described above. Thanks for any help anyone can provide.
Not sure I entirely understand your question, but it looks to me that it might be a candidate for datatemplateselector.
Basically, you use an ItemsControl bound to your result collection and then - using a datatemplateselector - you swap in the appropriate template to display the item based upon a code inspection.
That will let you present all the results in a single list.
If you want to display your results in a tabs, I would present a collection of each result type in your viewmodel. So you have a Users collection and a seperate Products collection. Then you can bind individual data grids to each template.
If you want to then hide the tabs when no results are present, add a data trigger using the expression.interactivity namespace to trigger the visibility of each tab page based on its respective collection count.
One more thing, if you want to create tab items dynamically, i.e. One tab for each search - the tab control has an ItemSource property. If you group each search result into an object an expose an observable collection of that object, you can bind that to your tab control and have it create tab items for each search result. Just make that object contain a collection of actual results and you should be able to create a itemscontrol as mentioned here already.
Sorry if this appears a bit of a mind dump, but like I said - not sure if I entirely get the question :)
Rather then chuck a load of code snippets in, there a plenty of samples just a google away if anything sounds helpful.

Conditionally validate Dynamically generated Controls in Silverlight

I am having a form with different type of controls like Text Box, Drop downs, Check box, Radio buttons etc. All these controls are loaded dynamically from database at run time.
I want to perform validation on Text box on conditional basis. For example, If we have selected any value in drop down, then you must have to fill details in Text box. Otherwise text box details are not required.
I am open to use database to perform this task and I am using MVVM pattern in my project.
Any help on this is highly appreciated.
Thanks.
(I started this as a comment, but it ended up being too long).
In theory you have access to all these controls and their values in your ViewModel.
Without knowing the specifics of your program, it's difficult to suggest anything useful, but in essence you need to expose some more properties from your ViewModel (probably boolean) which will be calculated based on the values in your controls. Then you need to bind IsEnabled properties on your controls to these new properties.
Sounds simple, but I think you have some architectural problems which will make it difficult to implement what I suggested above. In order for this to work and automatically update your controls whenever other controls' content change, your ViewModel needs to implement INotifyPropertyChanged and raise PropertyChanged event every time you update one of those boolean properties.
I think what you're trying to do could be achieved with ItemsControl and DataTemplates (and maybe DataTemplateSelectors). This will allow you to store "data" in your ViewModel (say List or something more specific) without referencing the actual Controls and the relevant DataTemplates will add the right controls for different data types you have in your ViewModel.

Change the auto-complete behaviour of a textbox

I have two doubts about the autocomplete feature of textboxes in C#.
First, I want to display the full list, not only the ones that start with the given text, and secondly I want to prevent the auto-complete of specific options (some are category titles).
I've been checking the textbox properties and there's nothing related to it, so probably the main question could be, Is there a way to modify / override the textbox events in order to handle the auto-complete actions? (I don't know if it applies to show the full list too)
I assume you're asking about a winforms textbox, as I dont think the WPF textbox supports autocomplete at all.
The base TextBox class will not support doing what you want, so you could in theory attempt to override all of the functionality in the TextBox class to do what you want, but the better idea would be to create a new custom control that inherits from TextBoxBase and implement the autocomplete behavior the way you want it.
I'm not sure about displaying the full list (perhaps a combobox or similar is more suited to this?) but you can definitely do something like this to swap which list of possible items can be displayed.
Another option, though one I like less, is to remove items you don't want to display at a given time from the collection dynamically, like this: textBox.AutoCompleteCustomSource.Remove("ACategoryTitle")
I could foresee that approach having many problems with trying to rebuild the list constantly. I would probably create a subclass of AutoCompleteStringCollection that wraps some LINQ code to nicely select the union of some lists and not others to display in the textbox.
I decided to build my own autocomplete tool with the help of a simple listbox and events, then I could achieve what I was expecting..
The CodingGorilla's answer probably leads to a better solution if you want something more decent, in my case for speed reasons I decided to do it that way but I'll mark his answer as the accepted in order to help other people who have the same doubt and they could consider that point..

C# ComboBox for IP addresses

I need a custom combo box that holds IP addresses. I have a custom control that holds an IP address(that actually is a panel with 4 textboxes). I already tried adding other controls to a normal combo box, such as a button and a textbox. I get no exceptions but I would expect to see the item in the drop-down list, instead i get a blank line for each item.
My first thoughts about this would be to extend the ComboBox control. What would you suggest?
A combo box is basically a textbox and a (usually) button-activated listbox combined for convenience. If it's not convenient you could implement your own dropdown functionality. Put a button next to your textboxes that display a listbox and when an item is selected from the listbox, put the values in the appropriate textboxes. In other words, don't try to extend the combo box, try to re-construct a similar control based on similar components.
It's not too difficult to override the ComboBox so I suppose you could create a custom ComboBox to show your own control that would be a container showing multiple of your IP Address controls.
Here's a blog article by JaredPar showing how to get started, just replace the m_form with your own custom container control.
You can hold the ip-addresses in a listbox, even in a combobox or what ever you want. Do not forget how your coding is, if you have an oop based tcp-socket program than no cross thread exception will be thrown. the codes shall be like ListBox.Items.Add(ipaddress) or ComboBox.Items.Add(ipaddress) ...
In controls you may hold only the ip-addresses, if you want to store the socket objects use Dictionary ... Your answer is not clear, so i've answered on possibly situations.

Categories