473,406 Members | 2,343 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,406 software developers and data experts.

Combo box value change

Hi,

I have a combobox that contains values from a database.
What i want to do is write code that will execute an sql
statement each time the value of the combobox is changed.
I want to do this so i can enter the values returned from
these queries into another 2 combo boxes i have.
Can anyone give me any guidence on this. I am a beginner
and have no idea of where to start.

Any help would be fab :o)
Nov 20 '05 #1
9 6304
Cor
Hi Tonya,

On the event "index_changed" from the combobox (that is automaticly made as
you push on it in the designer) you take the value from the combobox.text

Something like this

dim SqlString as string ="SELECT * FROM mydatabase WHERE myselectitem = '"
& combobox.text & "'"

And with that you can read your data (by datareader or dataadaper or
whatever way you want)

There are a lot of other ways to make it more sophisticated but I would not
do that till you know how to do this.

Cor

I have a combobox that contains values from a database.
What i want to do is write code that will execute an sql
statement each time the value of the combobox is changed.
I want to do this so i can enter the values returned from
these queries into another 2 combo boxes i have.
Can anyone give me any guidence on this. I am a beginner
and have no idea of where to start.

Nov 20 '05 #2
thx for your help.

i just wanted to ask if it is poosible to use variables,
(as u did in your query ---MySelectedItem) within a
query? do i just declare it further up in the code?
Will the query recognise that it needs a value from the
user.

thx for your time

-----Original Message-----
Hi Tonya,

On the event "index_changed" from the combobox (that is automaticly made asyou push on it in the designer) you take the value from the combobox.text
Something like this

dim SqlString as string ="SELECT * FROM mydatabase WHERE myselectitem = '"& combobox.text & "'"

And with that you can read your data (by datareader or dataadaper orwhatever way you want)

There are a lot of other ways to make it more sophisticated but I would notdo that till you know how to do this.

Cor

I have a combobox that contains values from a database.
What i want to do is write code that will execute an sql statement each time the value of the combobox is changed. I want to do this so i can enter the values returned from these queries into another 2 combo boxes i have.
Can anyone give me any guidence on this. I am a beginner and have no idea of where to start.

.

Nov 20 '05 #3
Cor
Hi
Tonya the selected _index_changed is fired when you fill the combobox.

(Put a switch, boolean, flag to prevent that that happens while loading it)
You can set that to false when the combobox is filled with the items. That
is the same with all the other comboboxes.

(There are more ways to do this, but this is the simplest)

And when the user pushes on the dropdownbutton and selects.
So when you set the query in that event, it only can be fired when the user
select something.

If you don't understand it, I will make a little example.

Cor
Nov 20 '05 #4
Hi Cor

Im sorry i am still confused on what u mean. I think that
example may be required :o)
Sorry to keep bugging u.

This is the downfall of trying to explain anything to a
complete beginner!!!


-----Original Message-----
Hi
Tonya the selected _index_changed is fired when you fill the combobox.
(Put a switch, boolean, flag to prevent that that happens while loading it)You can set that to false when the combobox is filled with the items. Thatis the same with all the other comboboxes.

(There are more ways to do this, but this is the simplest)
And when the user pushes on the dropdownbutton and selects.So when you set the query in that event, it only can be fired when the userselect something.

If you don't understand it, I will make a little example.

Cor
.

Nov 20 '05 #5
Cor
Angelina,

I made this example, it is partly copied and partly typed, so check the
errors yourself.

I hope this helps a little bit.

Cor

\\\
imports System.data.sqlclient.
private swcombo as boolean
Private Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
dim i as integer
For i = 10 To 1000 Step 10
combobox1.Items.Add(i.ToString)
Next
combobox1.SelectedIndex = 1
swcombo = true
End Sub
Private Sub combobox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles combobox1.SelectedIndexChanged
if swcombo then
Dim connString as String = "a nice connection string"
Dim sqlString As String
sqlString = "SELECT * FROM mydatabase WHERE myselectfield = '" &
cmbSize.Text & "'"
Dim Conn As New SqlConnection(connString)
Dim cmd As New SqlCommand(sqlString, Conn)
Dim dataset1 As New DataSet
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
da.Fill(dataset1)
end if
End Sub
///
Nov 20 '05 #6
Hi Cor and Tonya
I recently stumbled across the
SelectionChangeCommitted event of a combo.
As far as I have tested it this far (which I admit is not much) this event
is not fired when you fill the combo but otherwise it works in the same way
as the SelectedIndexChanged.
This might free you from the switches.
Cor, if this is incorrect I would like to hear your experiences with
SelectionChangeCommitted

Best regards

Jan

"Cor" <no*@non.com> skrev i en meddelelse
news:uB****************@TK2MSFTNGP12.phx.gbl...
Hi
Tonya the selected _index_changed is fired when you fill the combobox.

(Put a switch, boolean, flag to prevent that that happens while loading it) You can set that to false when the combobox is filled with the items. That
is the same with all the other comboboxes.

(There are more ways to do this, but this is the simplest)

And when the user pushes on the dropdownbutton and selects.
So when you set the query in that event, it only can be fired when the user select something.

If you don't understand it, I will make a little example.

Cor

Nov 20 '05 #7
Cor
Hi Jan,

I saw your answer in adonet, I thought I tryed it also once before, but I
do it today again.
That what I did write to Tonya was rough written not tested and copied from
2 applications

I am busy with a 2 comboboxen now, that are filled in that way, so I can try
it today.
And give you an answer.

Thanks,

Cor

I recently stumbled across the
SelectionChangeCommitted event of a combo.
As far as I have tested it this far (which I admit is not much) this event
is not fired when you fill the combo but otherwise it works in the same way as the SelectedIndexChanged.
This might free you from the switches.
Cor, if this is incorrect I would like to hear your experiences with
SelectionChangeCommitted

Nov 20 '05 #8
Cor
Hi Jan,

I tried it and it worked fine, I thought I knew it somehow but forgot it.

Because I was quiet sure, I told somebody who had a problem with it already
about it.

I can now remember it, because I can think on you when I do this the next
time or give somebody advice.

Thanks

Cor
Nov 20 '05 #9
If you are satisified I have confidence in using this solution in the
future.

Jan
"Cor" <no*@non.com> skrev i en meddelelse
news:uq**************@TK2MSFTNGP10.phx.gbl...
Hi Jan,

I tried it and it worked fine, I thought I knew it somehow but forgot it.

Because I was quiet sure, I told somebody who had a problem with it already about it.

I can now remember it, because I can think on you when I do this the next
time or give somebody advice.

Thanks

Cor

Nov 20 '05 #10

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

Similar topics

3
by: vgrssrtrs | last post by:
<html> <head> <script language="JavaScript"> <!-- /* *** Multiple dynamic combo boxes *** by Mirko Elviro, 9 Mar 2005 *** ***Please do not remove this comment
1
by: Giulio | last post by:
Hello, I have a continuous form with a combo box inside. From the combo box I can pick some values which, by the "after-update" event, change some other combo box values determined by a query....
6
by: Reggie | last post by:
Hi and TIA! I have a bound combobox with rowsource set to value list, limit to list=true and NotInList procedure to add(or not) a value the user types in. This works fine and it does add the...
8
by: Lyn | last post by:
Hi, Can anyone tell me how the initial value displayed in Combo Box is determined when a form is opened? I am loading the dropdown from one field ("CategoryName") of a table, with "ORDER BY ". ...
9
by: Edwinah63 | last post by:
Hi everyone, Please let there be someone out there who can help. I have two BOUND combo boxes on a continuous form, the second being dependent on the first. I have no problem getting the...
9
by: Vmusic | last post by:
Hi, I'm using MS Access 2002. I have a form with a combo box built from a query that returns one column, and that one column is the bound column. How do you use VBA to programmatically change...
2
by: Scott | last post by:
If I click the "Update" button on my form below, I can retrieve the value of my combo by using code in the FORM RESULTS section below. Therefore, if I choose the "Inside" option in my combo, I...
8
by: salad | last post by:
I was wondering how you handle active/inactive elements in a combo box. Let's say you have a combo box to select an employee. Joe Blow has been selected for many record however Joe has left the...
8
by: AA Arens | last post by:
Hi I do have a products table and products-parts table in my Access 2003 database and log all services into a form. I do have at least the following two combo boxes on my form: - Choose...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.