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

Bound ListBox Values

I posted this in the Visual Basic Forum, but I've been wondering if .NET might be a better place for it. I'm working in Visual Basic Microsoft Visual Studio .NET 2005.

I'm very new to the whole programming thing and I'm having a little trouble with the syntax of my code.

My code contains a bound listbox where the display member and value member are two different values. I want my program to cycle through the listbox and compare the value member of each item in the list box with a fixed value. My problem is I can't seem to find the syntax to grab the value of the item in the list box. I can't use DescriptionListBox.SelectedValue. Because the item is not selected. This is an example of some code I've tried, but it is not working.

For counting As Integer = 0 To DescriptionListBox.Items.Count - 1

If DescriptionListBox.Items.Item(counting).value = Me.DataSet.Table.Rows(i).Item(1) then


DescriptionListBox.SetSelected(counting, True)

end if
Next

I guess my question is what can I use in place of ListBox.SelectedValue, to capture the Value of a bound listbox's item that is not selected?
Feb 29 '08 #1
4 1460
SammyB
807 Expert 512MB
Just use the Items property. DescriptionListBox.Items(1) gives you the second item in the list. You can also use a for each loop. HTH --Sam
Expand|Select|Wrap|Line Numbers
  1.  Dim s As String
  2.  For Each s In DescriptionListBox.Items
  3.      MessageBox.Show(s)
  4.  Next s
  5.  
Feb 29 '08 #2
No such luck. My ListBox is bound to a table. Therefore the program reads items as a system.data.datarowview. If I try and put a .ToString on it or in someway convert it to a string, the program gives me "System.Data.DataRowView" as my listbox item.

Just use the Items property. DescriptionListBox.Items(1) gives you the second item in the list. You can also use a for each loop. HTH --Sam
Expand|Select|Wrap|Line Numbers
  1.  Dim s As String
  2.  For Each s In DescriptionListBox.Items
  3.      MessageBox.Show(s)
  4.  Next s
  5.  
Mar 1 '08 #3
SammyB
807 Expert 512MB
Ah, I'm more senile than you. Not exactly sure how to do it in VB, but in C#, it is
Expand|Select|Wrap|Line Numbers
  1. DataRowView dr = (DataRowView)DescriptionListBox.Items[0];
  2. String valueColumn = DescriptionListBox.ValueMember;
  3. MessageBox.Show(dr[valueColumn].ToString());
  4.  
Hopefully, that will get you started. --Sam
Mar 1 '08 #4
You are amazing. It worked. Here is the code I used for VB
Expand|Select|Wrap|Line Numbers
  1. Dim anewtry As DataRowView
  2. anewtry = DescriptionListBox.Items(counting)
  3. Dim blahblah As String
  4. blahblah = DescriptionListBox.ValueMember
  5. MsgBox(anewtry(blahblah))
  6.  
Thanks a ton.
Mar 3 '08 #5

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

Similar topics

19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
1
by: VB Programmer | last post by:
I have a listbox which is data bound to a query that incorporates several tables. I want to be able to update the listbox with new items (from another "master" listbox), remove existing items,...
2
by: Daryll SHatz | last post by:
What object is returned by a bound (to a DataSet) ListBox when it is iterated? Listbox.DataSource = DataSet1.MyTable ListBox.DisplayMember = "Col1" ListBox.ValueMember = "Col2" Dim s as...
3
by: David L Wright II | last post by:
I have a data bound listbox that I want to select multiple lines then process each line. I bound a two column datatable to the listbox and set the DisplayMember property to the appropriate column...
0
by: Dave | last post by:
Hi all, I have a listbox that is complex bound by an arraylist. The problem is that when I delete an object from the arraylist, the listbox does not reflect those changes. I tried refreshing...
3
by: Richard Albrecht | last post by:
I have been trying to figure out for days on how to read values from a Bound ListBox. The listBox gets the values from an Access Table. I can read values fine for Non-Bound ListBoxes, But the...
0
by: Tony Botelho | last post by:
I am fairly new to VB.NET and I am having some difficulty working with a bound listbox. On a simple form, I open a connection to my database and load a dataser. I then bind a listbox to the the...
3
by: Jay Ruyle | last post by:
I'm trying to figure out a way to list several items in a listbox and let the user select any number of items in the listbox. I have tried to code in the items as bitwise items but all it stores...
0
by: Frnak McKenney | last post by:
Can I use a bound ComboBox for both browsing and editing? I'm working on a small, standalone database application using Visual C#.NET 2003 and an Access data file. In order to keep the number...
17
by: SenileOwl | last post by:
I'm very new to the whole programming thing and I'm having a little trouble with the syntax of my code. My code contains a bound listbox where the display member and value member are two different...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.