Results 1 to 6 of 6

Thread: how to use datdagrid without binding a datasource?

  1. #1

    Thread Starter
    Hyperactive Member temp_12000's Avatar
    Join Date
    Jan 2004
    Location
    LA, USA
    Posts
    411

    Unhappy how to use datdagrid without binding a datasource?

    how to use datdagrid without binding a datasource? for example, I want to have a datagrid of 10x10 cells in which put some computation results. In VB6, we can set .rows and .columns to set the number of rows and columns. However, I can not find out how to do it in Vb .NET. Thanks. It looks like VB .NET makes some simple things very complex.



  2. #2
    Lively Member
    Join Date
    Jul 2003
    Location
    Kuala Lumpur (Malaysia)
    Posts
    92

    Hmmm...

    You cannot use the datagrid to put the data directly. You have to use dataset.

  3. #3
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    if i understand the q correctly, you want to put data to a grid. hehehe. just create a datatable and bind that to the grid. i don't know a way how do a putting data without a datatable/set objects

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.       Dim dt As New DataTable()
    3.       Dim i, j As Integer
    4.       For i = 0 To 9
    5.          dt.Columns.Add()
    6.       Next
    7.       For i = 0 To 9
    8.          Dim r As DataRow = dt.NewRow
    9.          For j = 0 To 9
    10.             r(j) = j * i
    11.          Next
    12.          dt.Rows.Add(r)
    13.       Next
    14.  
    15.       DataGrid1.DataSource = dt
    16.    End Sub
    hope this helps, if not sorry.

  4. #4
    Lively Member
    Join Date
    Jun 2004
    Location
    Philippines
    Posts
    125
    haha! nice picture you got there, brownmonkey!

    anyway, i'm not sure if this is similar to what temp_12000 is asking but i'll ask it just the same. See, i have 2 forms and the main form has a datagrid which when i doubleclick on a row, the data in the productid row will appear on my next form with all of the details of that productid in different textboxes. Now,i can edit that row in my next form. My problem now is, how can i transfer the edited data from my second form to the same row of my datagrid from my first form? i'm thinking of using a datatable which i'll bind to my datagrid but i'm not sure if that will work. also, i don't know how to put it in code.do you know how i can go about this?if so, could you show me how?please help.thanks a lot!

  5. #5
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    i don't know much about this thing siomai mate. dunno if this helps. hehehe.

    form1
    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 DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
    13.       Dim r As DataRow = dt.Rows(DataGrid1.CurrentRowIndex)
    14.       Dim f As New Form2()
    15.       f.xSet(r(0).ToString, r(1).ToString, r(2).ToString)
    16.       f.ShowDialog()
    17.       r(0) = f.xGet()(0)
    18.       r(1) = f.xGet()(1)
    19.       r(2) = f.xGet()(2)
    20.    End Sub
    form2
    VB Code:
    1. Dim text1, text2, text3 As String
    2.    Public Sub xSet(ByVal text1 As String, ByVal text2 As String, ByVal text3 As String)
    3.       Me.text1 = text1
    4.       Me.text2 = text2
    5.       Me.text3 = text3
    6.    End Sub
    7.  
    8.    Public Function xGet() As String()
    9.       Return New String() {text1, text2, text3}
    10.    End Function
    11.  
    12.    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    13.       TextBox1.Text = text1
    14.       TextBox2.Text = text2
    15.       TextBox3.Text = text3
    16.    End Sub
    17.  
    18.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    19.       text1 = TextBox1.Text
    20.       text2 = TextBox2.Text
    21.       text3 = TextBox3.Text
    22.       Close()
    23.    End Sub
    hope this helps.

    and oh, btw... thanks for admiring my pic.

  6. #6
    Lively Member
    Join Date
    Jun 2004
    Location
    Philippines
    Posts
    125
    haha..yeah! it's amusingly cute!

    i'll try this one out...thanks a lot!

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