Page 1 of 2

vb.net textfile help.

Posted: Tue Jul 23, 2013 8:34 pm
by Mark
Hello,

This is the code i use to load all my customers names from my text file in to the list box
Code: Select all
	Dim i As Short
		
		lstDetails.Items.Clear()
		
		For i = 1 To numrecs
			With CustArray(i)
                lstDetails.Items.Add(.CustName)

			End With
		Next 
		
how do i get it to show the selected item's name in to a text box..

This is my full code for my page.
Code: Select all
Option Strict Off
Option Explicit On
Friend Class frmViewCust
	Inherits System.Windows.Forms.Form
	Dim numrecs As Short
	
	Private Sub cmdMain_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdMain.Click
		Me.Close()
		frmMenu.Show()
		
	End Sub
	
	Private Sub cmdSearch_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSearch.Click
		Dim i As Short
		Dim searchname As String
		
		lstDetails.Items.Clear()
		
		searchname = InputBox("Enter name to search for", "Find Customer")
		searchname = UCase(searchname)
		
		For i = 1 To numrecs
			With CustArray(i)
				If searchname = .CustName Then
					lstDetails.Items.Add(.CustName)
					lstDetails.Items.Add(.Address)
					lstDetails.Items.Add(.Town)
					lstDetails.Items.Add(.Phone)
					Exit Sub
				Else : MsgBox("No record for this customer")
				End If
			End With
		Next 
		
	End Sub
	
	Private Sub cmdViewAll_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdViewAll.Click
		Dim i As Short
		
		lstDetails.Items.Clear()
		
		For i = 1 To numrecs
			With CustArray(i)
                lstDetails.Items.Add(.CustName)

			End With
		Next 
		
	End Sub
	
	Private Sub frmViewCust_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		Dim Booking As BookingRecord
		
		Filename = My.Application.Info.DirectoryPath & "\fish.dat"
		
		FileOpen(1, Filename, OpenMode.Input)
		Do While Not EOF(1)
			numrecs = numrecs + 1
			Input(1, Booking.DateOfBooking)
			Input(1, Booking.BookingName)
			CustArray(numrecs).CustName = Booking.BookingName
			Input(1, Booking.BookingAddress)
			CustArray(numrecs).Address = Booking.BookingAddress
			Input(1, Booking.BookingTown)
			CustArray(numrecs).Town = Booking.BookingTown
			Input(1, Booking.BankOrBoatBooking)
			Input(1, Booking.ContactPhoneNumber)
			CustArray(numrecs).Phone = Booking.ContactPhoneNumber
			Input(1, Booking.DayOrEveningSession)
			Input(1, Booking.OutBoard)
			Input(1, Booking.NumberFishing)
			Input(1, Booking.BankOrBoatCost)
			Input(1, Booking.OutboardCost)
			Input(1, Booking.TotalCostForGroup)
		Loop 
		FileClose(1)
    End Sub

  
End Class

Re: vb.net textfile help.

Posted: Tue Jul 23, 2013 8:46 pm
by Dummy1912
try this :)
Code: Select all
 Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
For i = 0 To ListBox1.SelectedItems.Count - 1
 TextBox1.Text = ListBox1.SelectedItems.Item(i).ToString()
 Next
    End Sub


Re: vb.net textfile help.

Posted: Tue Jul 23, 2013 8:52 pm
by Mark
i done this
Code: Select all
    Private Sub lstDetails_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstDetails.SelectedIndexChanged

        Dim i As Integer

        For i = 0 To lstDetails.SelectedItems.Count - 1
            TextBox1.Text = lstDetails.SelectedItems.Item(i).ToString()
        Next

    End Sub
what if i wanted to show the rest of the information in textboxe's?

Re: vb.net textfile help.

Posted: Tue Jul 23, 2013 9:02 pm
by visualtech
if it's a simple listbox (not a listview) try this:
Code: Select all

Dim str As String = ListBox1.SelectedItem.ToString()
TextBox1.Text = str

If it's a list view and the customer's name is the second row, use this:
Code: Select all

Dim str as string = ""

For Each lst as ListViewItem in lstView.SelectedItems
str = lst.Subitems(0).Text
Next

TextBox1.text = str


Re: vb.net textfile help.

Posted: Tue Jul 23, 2013 9:04 pm
by Mark
what i ment was i have the textbox1 working i was meaning i have a field called address etc and want to show that aswell once they select a name from the list box.?

Re: vb.net textfile help.

Posted: Tue Jul 23, 2013 9:08 pm
by visualtech
ohh then use a ListView. select the View to Detail and then enter data to it. (Then extract the data as i told you)

Re: vb.net textfile help.

Posted: Tue Jul 23, 2013 9:16 pm
by Mark
cant i use the listbox?.

Re: vb.net textfile help.

Posted: Tue Jul 23, 2013 9:43 pm
by visualtech
you can but it would look ugly and by that I mean, REALLY UGLY

Re: vb.net textfile help.

Posted: Tue Jul 23, 2013 9:54 pm
by Mark
it's just im trying to do it that way as its the last of a college project?.

Re: vb.net textfile help.

Posted: Tue Jul 23, 2013 10:08 pm
by visualtech
THe items will look something like this

John Doe Acme, Inc. 14-Downtown

etc.. How ever, to give it a simple yet clean look:

Use uxtheme.dll (Vista and above) with the SetWindowTheme function.