473,607 Members | 2,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bound ListBox Values

27 New Member
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 DescriptionList Box.SelectedVal ue. 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 DescriptionList Box.Items.Count - 1

If DescriptionList Box.Items.Item( counting).value = Me.DataSet.Tabl e.Rows(i).Item( 1) then


DescriptionList Box.SetSelected (counting, True)

end if
Next

I guess my question is what can I use in place of ListBox.Selecte dValue, to capture the Value of a bound listbox's item that is not selected?
Feb 29 '08 #1
4 1480
SammyB
807 Recognized Expert Contributor
Just use the Items property. DescriptionList Box.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
SenileOwl
27 New Member
No such luck. My ListBox is bound to a table. Therefore the program reads items as a system.data.dat arowview. If I try and put a .ToString on it or in someway convert it to a string, the program gives me "System.Data.Da taRowView" as my listbox item.

Just use the Items property. DescriptionList Box.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 Recognized Expert Contributor
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
SenileOwl
27 New Member
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
4083
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 the code that implements managing unbound controls on forms given the superior performance of unbound controls in a client/server environment. I can easily understand a newbie using bound controls or someone with a tight deadline. I guess I need...
1
1787
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, etc... then update the db with the new contents of the listbox after the user clicks on a Save button. Not sure exactly how to do this. Any suggestions? Thanks.
2
5100
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 String For Each itm In ListBox.Items ' what goes here to output the display text for each item in the
3
3838
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 of the datatable. I set the SelectionMode property to MultiExtended. I am able to load and select multiple lines in the listbox but I can not figure out how to retrieve both columns for each line selected in the listbox. I know that there is...
0
1680
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 the listbox with no luck and, because it is already bound, I can't just delete the item directly from the listbox without an error (because it already has a datasource, you are not allowed to delete/add anything to the listbox directly). The...
3
8457
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 same code doesn't work for Bound, see below: Any one of these work for a non-bound listbox. Code:
0
1281
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 dataset and set the display member. I also connect some filed using databinding. I am able to choose an item from the listbox and edit it, but the listbox is not refreshing (only the original values are visible in the listbox). If I choose a...
3
2377
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 in the database is the top item in the listbox. How can I get the listbox to add all the bit values to be stored and also come out properly when viewed later? Example:
0
2005
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 of different screens down to a minimum, I'm trying to use the same Windows Forms for both browsing and for updating. This works fine for TextBoxes, but I'm running into problems with my DropDownLists (ComboBoxes).
17
2662
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 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...
0
7985
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8469
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8463
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8128
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5471
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3953
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4013
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2461
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 we have to send another system
0
1316
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.