Results 1 to 5 of 5

Thread: Datagrid expand on load ****resolved******

  1. #1

    Thread Starter
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228

    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

  2. #2
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    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

  3. #3

    Thread Starter
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228
    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

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    VB Code:
    1. dgEmployees.DataSource = myDataSet.Tables(0)

  5. #5

    Thread Starter
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228
    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
  •  



Click Here to Expand Forum to Full Width