473,320 Members | 1,974 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,320 software developers and data experts.

Using a Listview to Populate a combo box

Hi all

I am trying to Populate a combo box from a selection in an adjacent
Listview. The Listview lists as a string the field names of 4
different fields in tblFile. So far I can populate the combo box with
the correct number of records(only 4 in the test database) but the
data is the actual string being passed which is actually the right
field....just not the data in the field. Here is my code so far that
fills the combo box with the string Name.

' selects the field name used for the table tblFile
strID = lvSearchBy.SelectedItems(0).SubItems(1).Text
intID = CInt(Val(Trim(strID)))

'Gets field name from tblSearch
dbCmd.CommandText = "Select ActualName from tblSearch where IDKey = "
& intID & " "

dbConn.Open()
dbReader = dbCmd.ExecuteReader()
dbReader.Read()
strName = Trim(dbReader!ActualName)
dbConn.Close()
dbReader.Close()

dbConn.Open()
dbCmd.CommandText = "Select '" & strName & "' from tblFile order by '"
& strName & "' "

dbReader = dbCmd.ExecuteReader()
cboSearch.Items.Clear()
Do While dbReader.Read()
cboSearch.Items.Add(dbReader(0))
Loop
dbConn.Close()
Result in the combo box is:

wkrName
wkrName
wkrName
wkrName

There are 4 records in the test database.....so the number of records
are correct. I need to get the value of the wkrName field in the
table tblFile.
Your help would be apprieciated.

Thanks
Dave McKie
da*********@yahoo.com
9/30/2004
Nov 21 '05 #1
2 2874
Dave,

I think you need to remove the single-quote characters from this SQL Select
statement that you are building:

dbCmd.CommandText = "Select '" & strName & "' from tblFile order by '"
& strName & "' "

Like this:

dbCmd.CommandText = "Select " & strName & " from tblFile order by "
& strName

Hope this helps,

Kerry Moorman

"Dave McKie" wrote:
Hi all

I am trying to Populate a combo box from a selection in an adjacent
Listview. The Listview lists as a string the field names of 4
different fields in tblFile. So far I can populate the combo box with
the correct number of records(only 4 in the test database) but the
data is the actual string being passed which is actually the right
field....just not the data in the field. Here is my code so far that
fills the combo box with the string Name.
SNIP
dbConn.Open()
dbCmd.CommandText = "Select '" & strName & "' from tblFile order by '"
& strName & "' "

dbReader = dbCmd.ExecuteReader()
cboSearch.Items.Clear()
Do While dbReader.Read()
cboSearch.Items.Add(dbReader(0))
Loop
dbConn.Close()
Result in the combo box is:

wkrName
wkrName
wkrName
wkrName

There are 4 records in the test database.....so the number of records
are correct. I need to get the value of the wkrName field in the
table tblFile.
Your help would be apprieciated.

Thanks
Dave McKie
da*********@yahoo.com
9/30/2004

Nov 21 '05 #2

Hi Kerry,

Yea...that was it. A simple solution.
Thanks for replying so quickly.

Dave
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3

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

Similar topics

3
by: Neil Guyette | last post by:
Hello, Everyone, I'm trying to find information on how to populate a combo box using a SqlDataReader. I want to be able to set the value of the combo's value property different then the...
2
by: nejmay | last post by:
Help Please, I am taking a beginners VB.NET class and my next assignment making a Depreciation Calculator. I am suppose to use the built in functions SLN() and SYD() to perform the calus, option...
16
by: agrawal.solutions | last post by:
Hello Friends I am asking a very silly question but i dont find any solution fo this.. I am selectiong a recordset and want to populate a combobox where id would be inviseble and the content...
6
by: Beginner | last post by:
Hi, I'm trying to populate a TreeView from an existing and filled in ListView (lvwBuild). lvwBuild is a basic two column listview which can have any number of rows. I would like the first...
7
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
4
by: Rob | last post by:
I've constructed a user control inherited from ListView so I can handle and respond to scrolling events (to keep 2 listviews scrolling in sync). My user control includes an Overrides of WndProc...
1
by: indhu | last post by:
Hi all, I want 2 know, how to populate using 2 combo box to populate other field. right now am using click event of combo to populate the other field but i want to select both combo1 and combo2 ...
1
by: Monty M. | last post by:
Does anyone know how to perform two way data binding between a combo box and a listview. The listview is bound to a dataset table in code: Binding Bind = new Binding(); DataTable dt;...
1
by: kalaivani572 | last post by:
Can anyone tell me is there a way to populate a drop down/combo box in a listview control in C#.net. please help me ASAP
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.