|
-
May 1st, 2003, 04:19 PM
#1
Thread Starter
Addicted Member
Datagrid expand on load ****resolved******
I have a datagrdid on my form, on page load it calls a function to connect to a sql db and populate it as shown in the code below.
Code:
Dim myDataSet As New DataSet()
Dim connString As String = SQL_CONNECTION_STRING
Dim cnn As SqlConnection = New SqlConnection(connString)
Dim myCommand As SqlCommand = New SqlCommand("Select * FROM Orders", cnn)
myCommand.CommandType = CommandType.Text
cnn.Open()
Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter(myCommand)
Try
myDataAdapter.Fill(myDataSet, "Employees")
Catch
MsgBox("Error in connecting to database. Call Computer about to implode!!")
End Try
cnn.Close()
dgEmployees.DataSource = myDataSet
All works fine, problem is, i have to click on a node to open up the table to show all records. I want it to open with the datagrid completely expanded.
I do this in other apps but i bind all columns etc at design time, the table i am sending in changes dynamically, i just want to display all the data without having the user click on a plu sign to expand the table.
i have tried
Code:
dgEmployees.DataSource = myDataSet.DefaultViewManager
but to no avail
Any ideas?
Last edited by Halon; May 2nd, 2003 at 10:27 AM.
Soylent Green tastes like chicken
-
May 1st, 2003, 04:48 PM
#2
Frenzied Member
Also set the Datagrid DataMember to the table in your dataset you want to show.
You may also try
dgEmployees.Expand(-1)
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
May 2nd, 2003, 09:51 AM
#3
Thread Starter
Addicted Member
Thanks Lunatic3!
I actually did try the
Code:
dgEmployees.Expand(-1)
but all it did was get rid of user having to click on the plus sign. They still had to click on the table name. What you said about specifying the datamember sounds like an idea though.
What would be the syntax?
Soylent Green tastes like chicken
-
May 2nd, 2003, 10:03 AM
#4
VB Code:
dgEmployees.DataSource = myDataSet.Tables(0)
-
May 2nd, 2003, 10:26 AM
#5
Thread Starter
Addicted Member
Gracias!!
Worked like a charm. I was trying to use the table name instead of an index. Guess thats what happens when trying to use notepad to code in. (my computer is on fire).
Thanks guys!!
Soylent Green tastes like chicken
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
|