Results 1 to 2 of 2

Thread: datagrid rows

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2004
    Posts
    35

    datagrid rows

    is their a way to add rows to a datagrid during run time?
    so when a datagrid is shown you can click on a button and that their is a row added to the datagrid so you can fill it in ?

    any suggestions ???

    thnx
    greetings

  2. #2
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    do it with the datatable
    VB Code:
    1. Dim cn As New SqlConnection("user id=sa;password=password;initial catalog=northwind")
    2.    Dim da As New SqlDataAdapter()
    3.    Dim dt As New DataTable()
    4.    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5.       cn.Open()
    6.       da.SelectCommand = New SqlCommand("select * from territories", cn)
    7.       da.Fill(dt)
    8.  
    9.       DataGrid1.DataSource = dt
    10.    End Sub
    11.  
    12.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    13.       Dim r As DataRow = dt.NewRow
    14.       dt.Rows.Add(r)
    15.    End Sub

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