vb.net textfile help.

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
20 posts Page 1 of 2
Contributors
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

vb.net textfile help.
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
http://www.mbappz.com
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Re: vb.net textfile help.
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

visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

Re: vb.net textfile help.
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?
http://www.mbappz.com
User avatar
visualtech
VIP - Donator
VIP - Donator
Posts: 265
Joined: Sat Nov 19, 2011 2:19 pm

Re: vb.net textfile help.
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

Image
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

Re: vb.net textfile help.
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.?
http://www.mbappz.com
User avatar
visualtech
VIP - Donator
VIP - Donator
Posts: 265
Joined: Sat Nov 19, 2011 2:19 pm

Re: vb.net textfile help.
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)
Image
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

Re: vb.net textfile help.
Mark
cant i use the listbox?.
http://www.mbappz.com
User avatar
visualtech
VIP - Donator
VIP - Donator
Posts: 265
Joined: Sat Nov 19, 2011 2:19 pm

Re: vb.net textfile help.
visualtech
you can but it would look ugly and by that I mean, REALLY UGLY
Image
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

Re: vb.net textfile help.
Mark
it's just im trying to do it that way as its the last of a college project?.
http://www.mbappz.com
User avatar
visualtech
VIP - Donator
VIP - Donator
Posts: 265
Joined: Sat Nov 19, 2011 2:19 pm

Re: vb.net textfile help.
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.
Image
20 posts Page 1 of 2
Return to “Tutorial Requests”