Question get selected item details?

saquib189

New member
Joined
Dec 6, 2009
Messages
3
Programming Experience
1-3
Hello friend's, i'm beginner in vb.net and creating a billing project. In that i have two forms : Customer List and Customer Bill. In Customer List i added a listbox Control and a button, when the form loads it's display the customer list from the database. so i want that when i double click on the listbox or click on the show cust. details button after selecting customer. it's display the customer bill with all relevant field in the database in the bill table. the code of Customer List Load event are:
VB.NET:
Private Sub LoadListBox() 
Dim custAdaptor As New MemorialDataSetTableAdapters.BillTableAdapter 
Dim CustTable As New MemorialDataSet.BillDataTable custAdaptor.Fill(CustTable) 
With lstCustomer 
.Items.Clear() 
.DisplayMember = "Display Name" 
For Each CurrentRow As MemorialDataSet.BillRow In CustTable.Rows .Items.Add(CurrentRow.Name) 
Next 
End With 
End Sub 
Private Sub CustomerList_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
LoadListBox() 
End Sub
nd show details button code are:
VB.NET:
Private Sub btnShowDetails_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowDetails.Click 
If lstCustomer.SelectedItems.Count = 1 Then 
'confusion here how to load the details in bill form. 
Else If lstCustomer.SelectedItems.Count = 0 Then 
MessageBox.Show("You have to Select a Customer to display the details") Else 
MessageBox.Show("You have Selected too many Customers") 
End If 
End If 
CustomerBill.Show() 
End Sub

so when i click on show details button it redirect to bill form and display the result. but in vb only event and raiseEvent work not redirection. so plz help me. to solve this. or plz give me a link that have solution for this. thank you
 
Instead of loading the data in manually you should use data-binding. Add a DataSet, TableAdapter and BindingSource to your form in the designer. Bind the BindingSource to the DataSet and appropriate DataTable and bind the ListBox to the BindingSource. Loading your data then becomes:
VB.NET:
BillTableAdapter1.Fill(MemorialDataSet1.BillDataTable)
To get the row that corresponds to the user's selection you simply get the Current property of the BindingSource. It returns a DataRowView, which you can use directly or, if you want, get its Row property to get a DataRow.
 

Latest posts

Back
Top