473,473 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Combobox Population (VB 2005 Express)

Prewarning: I'm a newbie at VB. I just got done reading _Beginning
Visual Basic 2005_ (wrox) and I'm trying to put some of the things in
there to use.

I have a form where I can page through the records of a database, one
at a time. This form allows me to add new records, update records and
delete records. There are three items displayed on the form:
Application, Agency, and Database. Application is a databound textBox,
Agency and Database are databound comboBoxes. My data comes from a SQL
Server database with a table for each item.

tblApplication:
appID
appName
agID
dbID

tblDatabase:
dbID
dbName

tblAgency:
agID
agName

The initial view of the form works great. As I page through the
records, the comboBoxes show the correct data. When I click the New
button. This clears the Application textBox and it sets the two
comboBoxes' selectedIndex to 0.

Here's where the problem occurs. If I click the Add button or the
Cancel button, the form repopulates the fields. The Application textBox
displays the proper application name but the comboBoxes show the
selectedIndex of 0. This only occurs on the first record. The rest of
the records show the proper data. This is not being updated in the
database.

Below is the code I've been using to do this. It's lengthy but I cut
out what I thought was irrelevant. Can anyone point out to me what I'm
doing wrong and what I need to do to do it right?

************************************************** ******
Dim objConnection As New SqlConnection("ConnectionString")
Dim objCurrencyManager As CurrencyManager
Dim objDataAdapter As New SqlDataAdapter(SQL1, objConnection)
Dim objAGDataAdapter As New SqlDataAdapter(SQL2, objConnection)
Dim objDBDataAdapter As New SqlDataAdapter(SQL3, objConnection)
Dim objDataSet, objAGDataSet, objDBDataSet As DataSet
Dim objDataView, objAGDataView, objDBDataView As DataView
Private Sub frmUserInfo_Load(removed system args) Handles Me.Load
FillDataSetAndView()
BindFields()
End Sub
Private Sub FillDataSetAndView()
objCurrencyManager = CType(Me.BindingContext(objDataView),
CurrencyManager)

objDataSet = New DataSet()
objDataAdapter.Fill(objDataSet, "applications")
objDataView = New DataView(objDataSet.Tables("applications"))

objAGDataSet = New DataSet()
objAGDataAdapter.Fill(objAGDataSet, "agency")
objAGDataView = New DataView(objAGDataSet.Tables("agency"))

objDBDataSet = New DataSet()
objDBDataAdapter.Fill(objDBDataSet, "database")
objDBDataView = New DataView(objDBDataSet.Tables("database"))
End Sub
Private Sub BindFields()
txtApplication.DataBindings.Clear()
cboAgency.DataBindings.Clear()
cboDatabase.DataBindings.Clear()

txtApplication.DataBindings.Add("Text", objDataView, "appName")

cboAgency.DataBindings.Add("Text", objDataView, "agName")
cboAgency.DataSource = objDataView
cboAgency.DisplayMember = "agName"
cboAgency.ValueMember = "agID"

cboDatabase.DataBindings.Add("Text", objDataView, "dbName")
cboDatabase.DataSource = objDataView
cboDatabase.DisplayMember = "dbName"
cboDatabase.ValueMember = "dbID"

fillDropDowns()
End Sub
Private Sub fillDropDowns()
'this is to populate the comboBoxes from their database tables.

cboAgency.DataSource = objAGDataView
cboAgency.DisplayMember = "agName"
cboAgency.ValueMember = "agID"

cboDatabase.DataSource = objDBDataView
cboDatabase.DisplayMember = "dbName"
cboDatabase.ValueMember = "dbID"
End Sub
Private Sub btnNew_Click(removed system args) Handles btnNew.Click
cboAgency.SelectedIndex = 0
cboDatabase.SelectedIndex = 0
txtApplication.Clear()
txtApplication.Focus()
End Sub
Private Sub btnCancel_Click(removed system args) Handles
btnCancel.Click
Dim intPosition As Integer
intPosition = objCurrencyManager.Position

FillDataSetAndView()
BindFields()

objCurrencyManager.Position = intPosition
End Sub
************************************************** ******

Thanks for your suggestions!

--
Jerry

Jul 11 '06 #1
1 3022

Jerry wrote:
Prewarning: I'm a newbie at VB. I just got done reading _Beginning
Visual Basic 2005_ (wrox) and I'm trying to put some of the things in
there to use.

I have a form where I can page through the records of a database, one
at a time. This form allows me to add new records, update records and
delete records. There are three items displayed on the form:
Application, Agency, and Database. Application is a databound textBox,
Agency and Database are databound comboBoxes. My data comes from a SQL
Server database with a table for each item.

tblApplication:
appID
appName
agID
dbID

tblDatabase:
dbID
dbName

tblAgency:
agID
agName

The initial view of the form works great. As I page through the
records, the comboBoxes show the correct data. When I click the New
button. This clears the Application textBox and it sets the two
comboBoxes' selectedIndex to 0.

Here's where the problem occurs. If I click the Add button or the
Cancel button, the form repopulates the fields. The Application textBox
displays the proper application name but the comboBoxes show the
selectedIndex of 0. This only occurs on the first record. The rest of
the records show the proper data. This is not being updated in the
database.

Below is the code I've been using to do this. It's lengthy but I cut
out what I thought was irrelevant. Can anyone point out to me what I'm
doing wrong and what I need to do to do it right?

Private Sub fillDropDowns()
'this is to populate the comboBoxes from their database tables.

cboAgency.DataSource = objAGDataView
cboAgency.DisplayMember = "agName"
cboAgency.ValueMember = "agID"

cboDatabase.DataSource = objDBDataView
cboDatabase.DisplayMember = "dbName"
cboDatabase.ValueMember = "dbID"
End Sub
I added cboAgency.SelectedValue =
BindingContext(objDataView).Current("agID") to the fillDropDowns() for
both cboAgency and cboDatabase and I get the effect I was looking for.

--
Jerry

Jul 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Lubomir | last post by:
Hi, I would like to ask, how different are C# 2005 Express Edition and C# within MS Visual Studio 2005. Than as well Visual Web Developer 2005 Express Edition and ASP within MS VS 2005. ...
10
by: Bonj | last post by:
Hi I installed .NET 2005 express edition, and am about to unnistall it again because it can't seem to be able to even insert a resource file into a project. Can anyone tell me is this right?...
3
by: Mark | last post by:
Anyone know of a list of features lacking in Web Developer 2005 Express that are already in VS.NET 2003? I realize they take a slightly different approach due to the new ASP.NET 2.0, but I'm...
7
by: ad | last post by:
I found that there is reporting service bundle with SQLSever 2005 express. Can VS2005 express can use the reporting service in SQLSever 2005 express?
6
by: Brian Henry | last post by:
Visual Basic 2005 Express: http://download.microsoft.com/download/f/c/7/fc7debaf-4513-4300-9e6a-8fe27be88cd1/vbsetup.exe Visual C# 2005 Express:...
1
by: Peter | last post by:
I've purchased VS.NET 2005 Standard and have tried to install SQL Server 2005 Express, but get the following error in the error log. Please could someone help me.... Microsoft SQL Server 2005...
10
by: kmich | last post by:
I am planning on learning C#. Would it be best to learn on a full version of 2003 Pro or 2005 Express. What would be the advantages/disadvantages? Thank you for your time.
2
by: kress1963nov22 | last post by:
I recently purchased a good MS book ("Build a Web Site Now") by Jim Buyens. It has the Express Edition of MS-Visual Web Developer 2005 on CD and also MS SQL Server 2005 Express Edition on the CD. A...
1
by: Marvinq | last post by:
I'm a newbie to asp.net, but I have been a programmer for years. I have a question that I'm hoping someone can give me a good answer for, I have been trying to set up a site remotely and I've...
2
by: cpchan | last post by:
Hello, Can I create a Web-based application (not a Web site) with Visual C# 2005 Express ? Or I have to use Visual Web Developer 2005 Express Edition, choose ASP.NET and then choose C# ? Are...
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,...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.