Results 1 to 7 of 7

Thread: What controls??

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2004
    Posts
    29

    Unhappy 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

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  3. #3
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    say we have form1 and form2. on form1
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.       Dim f As New Form2()
    3.       f.ShowDialog()
    4.       Dim s As Form2.authors = f.selecteditems
    5.       If Not IsNothing(s) Then
    6.          TextBox1.Text = s.id
    7.          TextBox2.Text = s.lname
    8.          TextBox3.Text = s.fname
    9.          TextBox4.Text = s.phone
    10.          TextBox5.Text = s.address
    11.          TextBox6.Text = s.city
    12.          TextBox7.Text = s.state
    13.          TextBox8.Text = s.zip
    14.          TextBox9.Text = s.contract
    15.       End If
    16.    End Sub
    and on form2
    VB Code:
    1. Dim cn As New SqlConnection()
    2.    Dim da As New SqlDataAdapter()
    3.    Dim dt As New DataTable()
    4.    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.       cn.ConnectionString = "user id=sa;password=password;initial catalog=pubs;"
    6.       cn.Open()
    7.       da.SelectCommand = New SqlCommand("select * from authors", cn)
    8.       da.Fill(dt)
    9.  
    10.       DataGrid1.DataSource = dt
    11.    End Sub
    12.  
    13.    Public Structure authors
    14.       Dim id, lname, fname, phone, address, city, state, zip, contract As String
    15.    End Structure
    16.  
    17.    Dim s As authors
    18.    Public ReadOnly Property selecteditems() As authors
    19.       Get
    20.          Return s
    21.       End Get
    22.    End Property
    23.  
    24.    Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
    25.       s.id = dt.Rows(DataGrid1.CurrentCell.RowNumber)(0)
    26.       s.lname = dt.Rows(DataGrid1.CurrentCell.RowNumber)(1)
    27.       s.fname = dt.Rows(DataGrid1.CurrentCell.RowNumber)(2)
    28.       s.phone = dt.Rows(DataGrid1.CurrentCell.RowNumber)(3)
    29.       s.address = dt.Rows(DataGrid1.CurrentCell.RowNumber)(4)
    30.       s.city = dt.Rows(DataGrid1.CurrentCell.RowNumber)(5)
    31.       s.state = dt.Rows(DataGrid1.CurrentCell.RowNumber)(6)
    32.       s.zip = dt.Rows(DataGrid1.CurrentCell.RowNumber)(7)
    33.       s.contract = dt.Rows(DataGrid1.CurrentCell.RowNumber)(8)
    34.       Close()
    35.    End Sub
    me dunno if this helps mate.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jul 2004
    Posts
    29
    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

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2004
    Posts
    29
    sorry, my mistake, i was overlooked!!

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jul 2004
    Posts
    29
    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

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jul 2004
    Posts
    29

    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
  •  



Click Here to Expand Forum to Full Width