473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How do I create a combobox that works like MS Access's

Seth Schrock
2,965 Expert 2GB
I am trying to create a front end program through Visual Studio 2012 using VB.Net for a database backend (both Access and SQL Server will be used for the backend). What I'm used to in MS Access is that the combo box has a Control Source property which tells it in which field to store the selected value. Then you have a Row Source property that allows you to query a second (related) table for possible values. I then bind the control to the primary key field of the related table, but show the text field. So I have two fields in the combobox, but the column sizes are 0 inches for the first column (makes it a hidden column) and then whatever size is needed to show the data that I want seen.

So far, I have been able to get the text for the list of options by using the DataSource property to list the binding source and then the DisplayMember property to select the field I want shown. I believe that the Text property under the DataBindings group would be the same as the control source in Access, however there are also SelectedItem and SelectedValue properties which I can't figure out what they are for.

I have read about multi-column comboboxes, but I'm not trying to display multiple columns, so I'm not sure if this is the route I need to follow.

Please let me know if my question is unclear.
Jun 21 '13 #1

✓ answered by zmbd

Someone correct me if I am wrong
vb.net is NOT my realm of expertese....

Seth,
From what I understand, unlike when you are doing this within the Access interface where the combobox can be linked to the data tablw, the combobox within vb.net has to have each item loaded into the control's list.

The one clear tutorial I found on this:

Note that the full article has step by step in the connection and the table setup etc; however, I think this is the main concept you're after:
Bind a ComboBox to a database lookup table in VB .NET
At run time, you still need to load and save the database data. In the form's Load event handler, call the data adapters' Fill methods to fill the DataSet. In this case, the program must load the UserTypes data first so it will be available when the Users table is loaded (the Users.UserType value must match a UserTypes.UserTypeId value).



' Load the data.
daUserTypes.Fill(dsUserData)
daUsers.Fill(dsUserData)



In the form's Closing event handler, the program saves changes to the Users table.


' Save any changes to the data.
daUsers.Update(dsUserData)

5 4176
zmbd
5,501 Expert Mod 4TB
Someone correct me if I am wrong
vb.net is NOT my realm of expertese....

Seth,
From what I understand, unlike when you are doing this within the Access interface where the combobox can be linked to the data tablw, the combobox within vb.net has to have each item loaded into the control's list.

The one clear tutorial I found on this:

Note that the full article has step by step in the connection and the table setup etc; however, I think this is the main concept you're after:
Bind a ComboBox to a database lookup table in VB .NET
At run time, you still need to load and save the database data. In the form's Load event handler, call the data adapters' Fill methods to fill the DataSet. In this case, the program must load the UserTypes data first so it will be available when the Users table is loaded (the Users.UserType value must match a UserTypes.UserTypeId value).



' Load the data.
daUserTypes.Fill(dsUserData)
daUsers.Fill(dsUserData)



In the form's Closing event handler, the program saves changes to the Users table.


' Save any changes to the data.
daUsers.Update(dsUserData)
Jun 24 '13 #2
Seth Schrock
2,965 Expert 2GB
I will give it a try, but I don't think that I do need to add the values at run-time as I already have the list of items being populated. I just can't get the equivalent to the Control Source property in Access to work. I think this is because I don't have a Bound To property.

Anyway, I'll give it a try and then let you know.
Jun 24 '13 #3
Seth Schrock
2,965 Expert 2GB
Yippee! That worked. For easy future reference, here are the property settings in the order they appear in the categorized view:

Two binding sources, one for each table (in my case, I have a tblEmployee and tblEmployeeType table)

(DataBindings) SelectedValue = TblEmployeeBindingSource - EmployeeType
This is the foreign key field

DataSource = TblEmployeeTypeBindingSource
DisplayMember = EmpType
ValueMember = EmpTypeID
These are the fields in the One side of the relationship.

You do have to use code to make the data get filled into the combobox, but not the individual items like I had seen other instructions do. Instead the code just forces the combobox to pull the data from the table.

Thanks again Z.
Jun 24 '13 #4
zmbd
5,501 Expert Mod 4TB
Cool-beans... I was taking a stab into a really dark portion of the cave!

Could you post the code you used to push the data or is that the same as covered within the link?
Jun 24 '13 #5
Seth Schrock
2,965 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. 'TODO: This line of code loads data into the 'LT_TestDataSet.tblEmployeeType' table. You can move, or remove it, as needed.
  2.         Me.TblEmployeeTypeTableAdapter.Fill(Me.LT_TestDataSet.tblEmployeeType)
  3.         'TODO: This line of code loads data into the 'LT_TestDataSet.tblEmployee' table. You can move, or remove it, as needed.
  4.         Me.TblEmployeeTableAdapter.Fill(Me.LT_TestDataSet.tblEmployee)
It is covered in the link. The code was already there, but I can't remember if I typed it in before while I was trying to figure it out, or if it inserted it for me when I added the BindingSources/Adapters/DataSets. I'll have to try recreating it to see exactly what happens. Not as easy as Access, but I'm having fun learning this :)
Jun 24 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: anonymous | last post by:
I've been trying to put a them, please help me out. Here's the major parts of my code: public Form1() { DataSet myDataSet = new DataSet("myDataSet"); DataTable testTable = new...
5
by: Quan Nguyen | last post by:
How can I obtain the textbox (editing field) control of the combobox? I tried combobox.Controls to obtain the collection of controls that the combobox contains but it turned out to be empty. Thanks.
9
by: Surrealist | last post by:
I need something likes as when I create an event procedure. I can use top-left and top-right dropdown list of code editor to select object and its exposed events respectively. Then, the IDE,...
4
by: Vish | last post by:
Hi, I need to make the text on a combobox that is disabled to be drawn with a black color. I was not able to find any help on this online. The drawItem seems to apply only for the dropdpwn...
1
by: Henry Jan | last post by:
Hi All, I want to create ComboBox and ListBox control with MAC style as this one on .NET: http://www.econtechvn.com/en/macuisuite_detail.htm However, it's really difficult with the...
5
donilourdu
by: donilourdu | last post by:
hi every one. I am doing project that holds Datagrid. I need a datagrid that can act as a combobox and Datetimepicker in seperate cells (Not in colums or Rows). I can able to create colum...
10
by: Doug Bell | last post by:
Hi I am still having problems with Tabbing through a DataGrid with a DataGridComboBox Column. I need to allow the User to Type the value into the ComboBox so consequently its ComboBoxStyle is...
0
by: Andrus | last post by:
I'm creating a .NET 2 winForms application. I'm need to create combobox or textbox which uses previously entered values for auto completion. For this, it saves last 10 entered values in isolated...
1
by: Andrus | last post by:
I need to enter null value from combobox to business object property. My combobox datasource does not contain ValueMember with null value. So I tried to create combobox which stores null to bound...
2
mafaisal
by: mafaisal | last post by:
Hello I am Using vb.net2005 My Doubt is When i bind database to datagridview how to create combobox in that my code is StrSQL = "Select SlNo,Fname,Relation,Age,gender,Others From EmpDet...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.