Results 1 to 12 of 12

Thread: [RESOLVED] Scroll bar for DataGridView

  1. #1

    Thread Starter
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Resolved [RESOLVED] Scroll bar for DataGridView

    I have a datagridview located in a tab of a tab control on a windows form. The data is populating to the grid with out any issues. My problem is that the sizing I'm making 2 of the column of data moves the last one partially off out side the normal size for the grid. I have Scrollbars set to both for the grid. But I do not get the Horizontal scroll bar. If I hover the mouse over the partially hidden cell I do see the full text in a tool tip.

    Am I missing some thing on setting the scroll bars here.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Scroll bar for DataGridView

    I sort of recall reading about something when you have locked columns.. is that the case here or no?

  3. #3

    Thread Starter
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Scroll bar for DataGridView

    I set the grid to no editable but did nothing to the columns
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Scroll bar for DataGridView

    I feel like this always has something to do with the columns and their sizing modes.

    What are they set to right now?

  5. #5

    Thread Starter
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Scroll bar for DataGridView

    Here is the code that load the grid:

    vb.net Code:
    1. Dim strSQL As String = String.Empty
    2.         strSQL &= "SELECT UserSQLId,PublicUse,StatementDescription,UserSQL  FROM UserSQLStatements "
    3.         strSQL &= "WHERE UserName = '" & mdlGeneral.strUserName.Replace("'", "''").Trim() & "';"
    4.         strSQL &= "SELECT UserSQLId,UserName,StatementDescription,UserSQL  FROM UserSQLStatements "
    5.         strSQL &= "WHERE UserName <> '" & mdlGeneral.strUserName.Replace("'", "''").Trim() & "' AND PublicUse = 1"
    6.         da = New clsDataAccess
    7.         Dim ods As New DataSet
    8.         ods = da.Return_DataSet(strSQL)
    9.         If ods IsNot Nothing Then
    10.             Me.dgPuiblicStatements.DataSource = Nothing
    11.             Me.dgUserStatements.DataSource = Nothing
    12.             Me.dgUserStatements.DataSource = ods.Tables(0)
    13.             Me.dgPuiblicStatements.DataSource = ods.Tables(1)
    14.             Me.dgPuiblicStatements.Columns(0).Visible = False
    15.             Me.dgPuiblicStatements.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
    16.             Me.dgPuiblicStatements.Columns(2).Width = 600
    17.             Me.dgPuiblicStatements.Columns(3).Width = 600
    18.             Me.dgUserStatements.Columns(0).Visible = False
    19.             Me.dgUserStatements.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
    20.             Me.dgUserStatements.Columns(2).Width = 600
    21.             Me.dgUserStatements.Columns(3).Width = 600
    22.             ods.Dispose()
    23.         End If
    24.         da.Dispose()
    25.         If mdlGeneral.errMessage.intErrNum <> 0 Then
    26.             MessageBox.Show("Error retrieving SQL Statements from the database.", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    27.         End If
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Scroll bar for DataGridView

    try not setting actual widths (for col 2 and 3), and set each column to AllCells for the size mode, and see if that gives you any different results.

  7. #7

    Thread Starter
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Scroll bar for DataGridView

    No difference just now can't see the last column since the one before is to large.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Scroll bar for DataGridView

    Hmmm. I'm not sure then, but I feel like it has to be something with the settings of the columns...

    If I put a DGV in a tabpage, and add 3 unbound columns, and set the individual columns AutoSizeMode property to AllCells, then I get this output

    Note screen shot on the left is the initial view, and the one on the right is scrolled all the way over, showing that column3 displays its full text and I have a scrollbar.

    the code is simply:
    Code:
            For i As Integer = 1 To 100
                DataGridView1.Rows.Add("ABCDEFGHIJKLMNOPQRSTUVWXYZ", _
                                       "ABCDEFGHIJKLMNOPQRSTUVWXYZ", _
                                       "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
            Next
    Attached Images Attached Images  

  9. #9

    Thread Starter
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Scroll bar for DataGridView

    What is odd is that I'm doing something similar in another form in the app (many more columns returned) and it works as expected. I'm not that worried on it right now since you can double click a row to actually edit the SQL statement to run if you want.

    The second column holds a discription of what the statement is suppoused to do that is actually the more important to see I guess.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  10. #10

    Thread Starter
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Scroll bar for DataGridView

    Thanks Matt this is solved. I never look at the size.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  11. #11
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [RESOLVED] Scroll bar for DataGridView

    hehe, yeah its one of those things easy to overlook. I would just dock it to fill in the tabpage, and that way if you change the tabpage size ever, the grid will change with it.

  12. #12

    Thread Starter
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: [RESOLVED] Scroll bar for DataGridView

    That is what I just did. The grids now expand with the page to fill the tab page in the same position.

    Working on another section now to allow you to start a trace on a selected SQL Server.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

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