Take ID from drop down list and drop details - c#

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

Related

Custom control - Property to add element to a binded DataSource

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.

Windows Form Combo Box display & values out of sync

I have developed a small application but ran into this problem, so I'm starting with a clean slate to try and isolate it. So far, I made a very simple Windows form (VS 2017) application connecting to an SQL data table. On the form, I have a combo box for selecting a table row that is bound to the data set. I have it displaying an order number, and have its value member as an EntryID number as shown, which is also the "selected value".
I also have a simple text box on the form displaying the EntryID.
When I run the app, the combo box initially displays an ordered list of order numbers like this:
Before selecting an item, if I scroll through the list using the form's tool bar selector, the EntryID text box value corresponds to the combo box value, so Ord40 selects the last data set row (where EntryID = 1003).
When an item is selected, however, the combo box list order changes. For example, after a few selections, I get:
But if I select the last display item, "Ord 20", I still get the data row EntryID = 1003. In other words, although the bound data set does not change, the combobox scrambles the displayed item. Put yet another way, if the combobox has a set of display fields and a corresponding set of value fields, the display field text get out of sync with the underlying value.
I hope that makes sense. This is straight, out of the box, no altered code on a fresh project, and I have tried different settings on the "selected value" property.
Any help would be much appreciated.
James
You are binding SelectedValue of the ComboBox to the same data source which you use as data source of the control. Setting DataSource is just for showing items in dropdown. Setting SelecetdValue if for changing the value of bound property/column.
You never want to bind SelectedValue to the same data source which you use for DataSource.
Just as a an example, assuming you have the following tables:
Product (Id, Name, CategoryId, Price)
Category (Id, Name)
Then if you want to show a ComboBox for CategoryId in the edit form of Product, the setup of the categoryIdComboBox should be:
DataSource: categoriesDataSource
DisplayMember: Name
ValueMember: Id
SelectedValue: productsBindigSource - CategoryId

Databound Combobox not unfocusing

I'm trying to make a databound combobox in a bindingnavigator. I want the options for the combobox to come from a different table and have a different display and value member.
So I have a member table and a group table and each member has a group determined by a fk_Group column. I want the combobox to be able to select from the currently existing options in the group table to set the member fk_Group to one of the pk_Groups that already exists.
So far I have the combobox properties set to
datasource: groupbindingsource
Display Member: GroupName
ValueMember: pk_Group
CausesValidation: False
Databinding SelectedValue: memberBindingSource - fk_Group
This makes sense to me and the combobox populates correctly but when I click an option I can't remove focus from it and the drop down starts behaving oddly, immediately snapping back up when it comes down.
I can get out of it by using the bindingnavigators arrows to go to a different record but then it clears the combobox.
Ideally I would like the combobox to populate with the current group name for that member as well as be able to select from a list of the other groups.
Thanks

how can i get an entry form based on selected drop down details in .net?

Based on drop down list details if we select the user in that list how can I get an entry form to fill that particular selected user details in the form?
Get the SelectedValue from the user dropdown list that will give you UserID
Use this UserID to get user details from the db table
For the user dropdown list create a SelectedIndexChanged event
Trigger the method that fills the user data in the form, from this event
Hope this helps...

Is two data sources for a DataGridView.ComboBoxColumn possible?

I have a DataGridView with several TextBoxColumns and one ComboBox column called 'combo' that holds the client type. The problem is that I'd like to show both the currently selected client-type value along with the dropdown client-type list to validate future changes by the user. In SQL Server, I have a DB with two table columns, 'client_type_dropdown.name' and 'clients.client_type'. The 'client_type_dropdown.name' column is a validation list. The 'clients.client_type' column contains the current client type for clients in the database. Is there a way to show in 'combo' both 'client_type_dropdown.name' and 'clients.client_type' , i.e., one source for the ComboBoxColumn dropdown and a different source for the textbox part of 'combo'? Or do I need to have two columns in my grid?
I appreciate your help.
I'm using a third party grid, but I usually handle this by setting the combo drop down style to DropDown instead of DropDownList. This will allow your original database value to display, even if it isn't in the list.
This also allows free typing of values into the combo field, so the trick after that is to validate the user input to make sure it matches a value in the list before you allow them to save updated values. You could play around with the LimitToList property of the combo to possibly save you doing the validation manually, but with most controls I have worked with it will give you more grief than help.

Categories