By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,957 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

How to import data in listbox by data that is inputted with inputbox

P: 6
Hello, I found hard to make my program to display the data that was stored by inputbox with listbox. To explain it better here is my code:

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Structure Userinfo
  3.         Dim membernumber As Integer
  4.         Dim memberforename As String
  5.         Dim membersurname As String
  6.         Dim memberfull As Boolean
  7.         Dim memberowe As Integer
  8.     End Structure
  9.  
  10.     Dim members(2) As Userinfo
  11.     Dim row As Integer
  12.     Dim chosen As Integer
  13.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  14.  
  15.  
  16.         For row = 0 To 2
  17.             members(row).membernumber = InputBox("Row " & row & ": Enter membership number")
  18.             members(row).membersurname = InputBox("Row " & row & ": Enter surname")
  19.             members(row).memberforename = InputBox("Row " & row & ": Enter forename")
  20.             members(row).memberfull = InputBox("Row " & row & ": Full member (0 for No, 1 for Yes)?")
  21.             members(row).memberowe = InputBox("Row " & row & ": Enter amount owed()")
  22.             lstbox.Items.Add(row)
  23.  
  24.  
  25.         Next
  26.  
  27.  
  28.     End Sub
  29.  
  30.     Private Sub lstbox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstbox.SelectedIndexChanged
  31.  
  32.         txtname.Text = members(row).memberforename + " " + members(row).membersurname
  33.         txtnumber.Text = members(row).membernumber
  34.         If members(row).memberfull Then txtfull.Text = "Y" Else txtfull.Text = "N"
  35.         txtowe.Text = members(row).memberowe
  36.  
  37.     End Sub
  38.  
  39. End Class


The problem is that it displays only the last "row" when you click on the listbox and that is what I don't understand- how to make display selection on listbox.
Feb 10 '14 #1

✓ answered by Luk3r

With just a couple of tiny adjustments I was able to get your code to work.

Replace:
Expand|Select|Wrap|Line Numbers
  1. For row = 0 To 2
with
Expand|Select|Wrap|Line Numbers
  1. For Me.row = 0 To 2

On your lstbox_SelectedIndexChanged, add:
Expand|Select|Wrap|Line Numbers
  1. row = lstbox.SelectedIndex.ToString
above all of your current code.

Share this Question
Share on Google+
2 Replies


100+
P: 299
With just a couple of tiny adjustments I was able to get your code to work.

Replace:
Expand|Select|Wrap|Line Numbers
  1. For row = 0 To 2
with
Expand|Select|Wrap|Line Numbers
  1. For Me.row = 0 To 2

On your lstbox_SelectedIndexChanged, add:
Expand|Select|Wrap|Line Numbers
  1. row = lstbox.SelectedIndex.ToString
above all of your current code.
Feb 10 '14 #2

P: 6
Thank you it worked, i really appreciate that.
Feb 10 '14 #3

Post your reply

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