|
-
Jul 24th, 2004, 11:43 PM
#1
Thread Starter
Junior Member
What controls??
Hi there,
i m a beginner in VB.Net.
i have 2 forms, F1 contains a ?Control and button1 & buton2. when the user click on the button1, the F2 with a datagrid display.The user can select a particular product by double click on the datagrid. The ProdName and Price will fill in the ?Control in F1. Of course this ?Control can display a list of prodName and price if the user click on the button1 and select more products. If the user click on Button2 it will show the total cost of the products.
What ?Control should i used ??
What is the coding to write on that ?Control??
Any help is appreciated.
Thanks,
viv
-
Jul 25th, 2004, 05:34 AM
#2
PowerPoster
Hi,
Presumably you fill the datagrid from more than one table (if you stick to Data Base Normal Form Rules).
If so, there are slightly involved ways of using a ListBox or a ListView, but why don't you just use two textboxes ( or probably Labels are more appropriate)?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 25th, 2004, 09:28 PM
#3
Fanatic Member
say we have form1 and form2. on form1
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New Form2()
f.ShowDialog()
Dim s As Form2.authors = f.selecteditems
If Not IsNothing(s) Then
TextBox1.Text = s.id
TextBox2.Text = s.lname
TextBox3.Text = s.fname
TextBox4.Text = s.phone
TextBox5.Text = s.address
TextBox6.Text = s.city
TextBox7.Text = s.state
TextBox8.Text = s.zip
TextBox9.Text = s.contract
End If
End Sub
and on form2
VB Code:
Dim cn As New SqlConnection()
Dim da As New SqlDataAdapter()
Dim dt As New DataTable()
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cn.ConnectionString = "user id=sa;password=password;initial catalog=pubs;"
cn.Open()
da.SelectCommand = New SqlCommand("select * from authors", cn)
da.Fill(dt)
DataGrid1.DataSource = dt
End Sub
Public Structure authors
Dim id, lname, fname, phone, address, city, state, zip, contract As String
End Structure
Dim s As authors
Public ReadOnly Property selecteditems() As authors
Get
Return s
End Get
End Property
Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
s.id = dt.Rows(DataGrid1.CurrentCell.RowNumber)(0)
s.lname = dt.Rows(DataGrid1.CurrentCell.RowNumber)(1)
s.fname = dt.Rows(DataGrid1.CurrentCell.RowNumber)(2)
s.phone = dt.Rows(DataGrid1.CurrentCell.RowNumber)(3)
s.address = dt.Rows(DataGrid1.CurrentCell.RowNumber)(4)
s.city = dt.Rows(DataGrid1.CurrentCell.RowNumber)(5)
s.state = dt.Rows(DataGrid1.CurrentCell.RowNumber)(6)
s.zip = dt.Rows(DataGrid1.CurrentCell.RowNumber)(7)
s.contract = dt.Rows(DataGrid1.CurrentCell.RowNumber)(8)
Close()
End Sub
me dunno if this helps mate.
-
Jul 26th, 2004, 06:15 AM
#4
Thread Starter
Junior Member
brown monkey
Thank you, but Dim s As Form2.authors = f.selecteditems (mine is Form2.Customers) has error as it is not defined. How do defined this??
Thanks again!
Viv
-
Jul 26th, 2004, 06:47 AM
#5
Thread Starter
Junior Member
sorry, my mistake, i was overlooked!!
-
Jul 26th, 2004, 05:21 PM
#6
Thread Starter
Junior Member
Hi,
i am having another problem.
when I used a comboBox to search for a customer. The customer data will display in a grid. BUT i always get the wrong data from what i selected from the grid. How can i solved this problem?
On form2
Private Sub btnSearchName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearchName.Click
With Me.dvCustomer.Table
With DataGrid1
.CaptionText = "Search by Last Name"
End With
If cboLastName.Text = "<ALL>" Then
.DefaultView.RowFilter = "CustLName like '%'"
Else
.DefaultView.RowFilter = "CustLName like '" & cboLastName.Text & "%'"
End If
If BindingContext(Me.DataSet11.Customers).Position < 0 Then
With DataGrid1
.CaptionText = "Database is empty !"
End With
End If
dt = .DefaultView.Table
End With
Me.DataGrid1.DataSource = dt
End Sub
Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
s.id = dt.Rows(DataGrid1.CurrentCell.RowNumber)(0)
s.Lname = dt.Rows(DataGrid1.CurrentCell.RowNumber)(1)
s.Fname = dt.Rows(DataGrid1.CurrentCell.RowNumber)(2)
s.title = dt.Rows(DataGrid1.CurrentCell.RowNumber)(3)
s.ic = dt.Rows(DataGrid1.CurrentCell.RowNumber)(4)
s.DoB = dt.Rows(DataGrid1.CurrentCell.RowNumber)(5)
s.deposit = dt.Rows(DataGrid1.CurrentCell.RowNumber)(6)
s.g = dt.Rows(DataGrid1.CurrentCell.RowNumber)(7)
s.jd = dt.Rows(DataGrid1.CurrentCell.RowNumber)(8)
s.add_1 = dt.Rows(DataGrid1.CurrentCell.RowNumber)(9)
s.add_2 = dt.Rows(DataGrid1.CurrentCell.RowNumber)(10)
s.postcode = dt.Rows(DataGrid1.CurrentCell.RowNumber)(11)
s.city = dt.Rows(DataGrid1.CurrentCell.RowNumber)(12)
s.state = dt.Rows(DataGrid1.CurrentCell.RowNumber)(13)
s.hp = dt.Rows(DataGrid1.CurrentCell.RowNumber)(14)
s.wp = dt.Rows(DataGrid1.CurrentCell.RowNumber)(15)
s.cp = dt.Rows(DataGrid1.CurrentCell.RowNumber)(16)
s.email = dt.Rows(DataGrid1.CurrentCell.RowNumber)(17)
Close()
End Sub
On form1
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Dim f As New frmCustSearch
f.ShowDialog()
Dim s As frmCustSearch.Customers = f.selecteditems
If Not IsNothing(s) Then
txtCustomerNo.Text = s.id
txtFirstName.Text = s.Fname
txtLastName.Text = s.Lname
cboTitle.Text = s.title
txtICNo.Text = s.ic
txtDoB.Text = s.DoB
txtDeposit.Text = s.deposit
If s.g = "M" Then
rbM.Checked = True
ElseIf s.g = "F" Then
rbF.Checked = True
End If
txtJoinDate.Text = s.jd
txtAddress_1.Text = s.add_1
txtAddress_2.Text = s.add_2
txtPostcode.Text = s.postcode
txtCity.Text = s.city
txtState.Text = s.state
txtHPhone.Text = s.hp
txtWPhone.Text = s.wp
txtCPhone.Text = s.cp
txtEmail.Text = s.email
End If
End Sub
Any help or examples is appreciated
viv
-
Jul 29th, 2004, 02:38 AM
#7
Thread Starter
Junior Member
Solved
problems solved!!!
Thanks guys
viv
Last edited by vivsm; Jul 29th, 2004 at 02:43 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|