I have a question about a user control I am creating.
The user control is only a ComboBox (with personal settings), with a datasource from a list from a database.
This list is very simple, it’s a list of vehicule type.
Currently, my database looks like this :
Id_Vehicule_Type Type Description
1 Car Car description
2 Truck Truck description
3 SUV SUV description
I can link my data to my user control, there’s no problem with that.
What I want is an option (property) to add or remove an “All” field.
If I create a new vehicule, I would like to be able to choose between Car/Truck/SUV.
If I search for a vehicule, I would like to be able to choose between Car/Truck/SUV/All. All will search for any vehicule type.
I already add a property to my user control, but for the moment, I retrieve the list from my database in the «Set» section of my property. It check if the _IncludeAll is true, then add a new item in the list before binding it, but I don’t find this really « well-made ».
List<VehiculeType> vehiculeTypes = Database.GetAllVehiculeType();
if (this._IncludeAll)
{
vehiculeTypes.Add(new VehiculeType(-1, "(All)"));
this.cbVehiculeTypes1.SelectedValue = -1;
}
I have no problem retrieving the id / type / description from my user control. I only can’t figure out how to manage this « option ».
Thank you and have a nice day.
Related
I have a drop down list (Works as needed) but I want to be able to add details to the list when I am selecting an ID it will show the customer/venue's name so you don't have to memorise every ID. I want to drop the name after its selected and keep the ID but I can't get it by itself.
Have you reviewed how to implement combo box control? I believe you can bind data source and then configure the "value" and display properties so that its selected index would reveal value (the Id in your data set) while the displayed portion would show a user friendly name of your data.
Refer to... https://learn.microsoft.com/en-us/dotnet/framework/winforms/controls/how-to-bind-a-windows-forms-combobox-or-listbox-control-to-data
I want to implement something like Google's search bar behavior for our application: user must be able to enter user name as free text and based on entered data system must provide a couple of suggestions on a popup bar based on already existent user names.
Here's the brief algorithm:
user enters some character to text edit box
system fires some changing event with web service call inside it that updates suggestions list data
Text edit must also provide an ability to enter and keep a free text to create new user, not just looking up for existent
I can't use devexpress's lookupeditds - they allow to keep only values, presented in datasource - even if new value has being processed inside ProcessNewValue by adding to datasource,
Changing event fires one more time with refreshing my datasource overwriting new unique value.
Now I am looking forward Combobox control. But looks like there is no ability to enter free text alongside with displaying suggestions popup.
I can't use devexpress's lookup edits - they allow to keep only values, presented in datasource - even if new value has being processed inside ProcessNewValue by adding to datasource,
I believe you're wrong here because you can use the DevExpress LookUpEdit with easy:
class AutoCompleteLookUpEdit : LookUpEdit {
List<string> suggestions = new List<string>();
public AutoCompleteLookUpEdit() {
Properties.DataSource = suggestions;
Properties.ImmediatePopup = true;
}
protected override void ProcessFindItem(KeyPressHelper helper, char pressedKey) {
suggestions.Clear();
// add search suggestions here depending on helper.Text value
suggestions.Add("google");
suggestions.Add("devexpress");
// ...
base.ProcessFindItem(helper, pressedKey);
}
}
Take a look at the How to create an editor with a dynamic autocomplete list for the detailed example.
P.S. You can use the AcceptEditorTextAsNewValue property to control whether or not lookup accepts entered text as valid value even it does not belong the underlying data source.
I am building a C# windows form that displays a listbox with some items to select from to a user. That selection will determine the criteria for a query. The query will return 2 fields, an ID and a description. I want to display the description in a second listbox on the form but use the ID for subsequent processing if that description is selected in the list box.
Here's some more details about what I am trying to do:
ListBox1
Accessories
Men's
Women's
Children
When the user selects 'Accesories' a query runs and returns:
1234 Belts
2345 Scarves
4566 Handbags
ListBox2 displays the descriptions
Belts
Scarves
Handbags
But when the user double clicks on Belts I want to add 1234 to a field in class instance. What kind of list should I put the results of the query into so that I can use it to add Items to my list box and still be able to know the ID?
Thanks!
Leslie
In the .NET list boxes, the item list is not just a list of strings, but objects. The component will use the string value of the object for display, but you can reference the ID when you look at the selected value.
Define a class thusly
class Choices
{
public string Name;
public int ID;
public override string ToString()
{
return name;
}
}
Populate the list with instance of this class, and you should be good to go.
Both WinForms and WPF are quite flexible. Just add the Accessory objects to the Items property. Or set DataSource to an existing list.
The default display is through ToString() but you can set DisplayMember to the name of a specific property.
You can get at the entire object through SelectedItem. And/or set ValueMember and read SelectedValue.
I have two tables, Customer and Address. One customer can have one or more addresses.
My view is a ListDetail with all my customers on the left as a list and the edition on the right.
Under the edition I have the "address area" with a list of addresses and an edition on the selected.
My problem is all my addresses are listed. I just want addresses with the matching customerId (selected on the first list).
Here is a drawing to help you see what I am talking about:
I can create a button on the first list that show a popup with the selected Id but I don't know how to put a parameter on my address collection.
Please tell me if you need more details.
Edit : A good example of what I want is the 'Roles' view created by default. I haven't found how to edit this view to see how it works but if you select a 'role' the list of users is updated to show only those that have this role.
If your two tables are related (meaning you've created a relationship between them in the table designer), then what you describe should happen automatically. Using the Add Screen wizard, you can tick the "related data" checkboxes for any related tables that you want to display for the selected item.
If you didn't tick the checkbox for a table, you can still drag the navigation property (created when you added the relationship), which is on the left side of the screen designer (with a + next to it).
To do it manually, you need to create a modeled query (a query based on a table, or on another query), to which you add an integer parameter, then add a filter based on that parameter.
I know how to connect to an access database and so on.
My question is, I want to select an item from a list box, and then it must search the access database for the item I selected and display all its contents in textboxes. For example:
In the listbox I have the following added:
Car 1
Car 2
Car 3
etc.
If I select Car 2, I want it to read the database and display all Car 2's properties in textboxes. So for example, once I select it, it can display Horsepower in a specific textbox, max speed in a specific text box, year model in a specific text box etc.
Could anyone help me out with this?
Assuming you have 1 textbox per property that will change whenever you select something different from your listbox here is what I would do. It sounds like you are already populating your listbox with some category from your database, possibly CarType. I would use LINQ to run a query to populate the results within the given textbox.
var query = from record in myTable.AsEnumerable()
where record.CarType == myListBox.SelectedValue
select record;
foreach (var record in query)
{
horsePower.Text = record.HorsePower;
//and so on
}
It sounds like you are setting up a custom control for this. However, I would suggest using a Data Grid to do what you are trying to do, instead of Text Boxes.
Have you tried using data binding?
listBox.DataSource = dataTableCars;
listBox.DisplayMember = "car_name";
listBox.ValueMember = "car_id";
txtBox.DataBindings.Add("Text",dataTableCars,"car_name");
txtBox.DataBindings.Add("Text",dataTableCars,"car_driver_name");
etc.