|
-
Oct 19th, 2004, 03:35 AM
#1
Thread Starter
Addicted Member
Using datagrid [Resolved]
Hi,
I get some data from Excel as a data array using the automation. I like to show those data in vb forms by using the datagrid.Shall I do that? If so , how? I need the coding..urgent!!!
Thanks
Last edited by haihems; Oct 20th, 2004 at 12:20 AM.
-
Oct 19th, 2004, 04:32 AM
#2
Hi
The DataGrid like its name suggests is designed to display bound data only. But you use it to display unbound manually.
the following code assume you have a datagrid on a form called DataGrid1.
On the form class declaration put this code
VB Code:
Private m_DataTable As New DataTable("MyTableName")
Private Sub InitData()
'Set up the DataTable
m_DataTable = New DataTable("TableName")
m_DataTable.Columns.Add(New System.Data.DataColumn("Column0"))
m_DataTable.Columns.Add(New System.Data.DataColumn("Column1"))
m_DataTable.Columns.Add(New System.Data.DataColumn("Column2"))
'Set up the datagrid control
DataGrid1.DataSource = m_DataTable
End Sub
Private Sub AddRow(ByVal sCol0 As String, ByVal sCol1 As String, ByVal sCol2 As String)
Dim NewRow As System.Data.DataRow = m_DataTable.NewRow()
NewRow(0) = sCol0
NewRow(1) = sCol1
NewRow(2) = sCol2
m_DataTable.Rows.Add(NewRow)
End Sub
on the form_load event put this :
VB Code:
InitData()
AddRow("1", "2", "3")
AddRow("a", "b", "c")
AddRow("cat", "dog", "mouse")
You can modify InitData and AddRow to include as many columns as you wish...
Regards
Jorge
"The dark side clouds everything. Impossible to see the future is."
-
Oct 19th, 2004, 10:06 PM
#3
Thread Starter
Addicted Member
Hi Jorge,
Thanks for your reply. Its very useful for me. One more thing, can I validate the user's input in datagrid???
regrads,
haihems.
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
|