|
-
Aug 24th, 2004, 04:35 PM
#1
Thread Starter
Hyperactive Member
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.
-
Aug 24th, 2004, 08:44 PM
#2
Lively Member
Hmmm...
You cannot use the datagrid to put the data directly. You have to use dataset.
-
Aug 24th, 2004, 09:26 PM
#3
Fanatic Member
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:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable()
Dim i, j As Integer
For i = 0 To 9
dt.Columns.Add()
Next
For i = 0 To 9
Dim r As DataRow = dt.NewRow
For j = 0 To 9
r(j) = j * i
Next
dt.Rows.Add(r)
Next
DataGrid1.DataSource = dt
End Sub
hope this helps, if not sorry.
-
Aug 26th, 2004, 10:52 PM
#4
Lively Member
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!
-
Aug 26th, 2004, 11:19 PM
#5
Fanatic Member
i don't know much about this thing siomai mate. dunno if this helps. hehehe.
form1
VB Code:
Dim cn As New SqlConnection("user id=sa;password=password;initial catalog=northwind")
Dim da As New SqlDataAdapter()
Dim dt As New DataTable()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cn.Open()
da.SelectCommand = New SqlCommand("select * from territories", cn)
da.Fill(dt)
DataGrid1.DataSource = dt
End Sub
Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
Dim r As DataRow = dt.Rows(DataGrid1.CurrentRowIndex)
Dim f As New Form2()
f.xSet(r(0).ToString, r(1).ToString, r(2).ToString)
f.ShowDialog()
r(0) = f.xGet()(0)
r(1) = f.xGet()(1)
r(2) = f.xGet()(2)
End Sub
form2
VB Code:
Dim text1, text2, text3 As String
Public Sub xSet(ByVal text1 As String, ByVal text2 As String, ByVal text3 As String)
Me.text1 = text1
Me.text2 = text2
Me.text3 = text3
End Sub
Public Function xGet() As String()
Return New String() {text1, text2, text3}
End Function
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Text = text1
TextBox2.Text = text2
TextBox3.Text = text3
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
text1 = TextBox1.Text
text2 = TextBox2.Text
text3 = TextBox3.Text
Close()
End Sub
hope this helps.
and oh, btw... thanks for admiring my pic.
-
Aug 27th, 2004, 12:13 AM
#6
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|