[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.
Re: Scroll bar for DataGridView
I sort of recall reading about something when you have locked columns.. is that the case here or no?
Re: Scroll bar for DataGridView
I set the grid to no editable but did nothing to the columns
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?
Re: Scroll bar for DataGridView
Here is the code that load the grid:
vb.net Code:
Dim strSQL As String = String.Empty
strSQL &= "SELECT UserSQLId,PublicUse,StatementDescription,UserSQL FROM UserSQLStatements "
strSQL &= "WHERE UserName = '" & mdlGeneral.strUserName.Replace("'", "''").Trim() & "';"
strSQL &= "SELECT UserSQLId,UserName,StatementDescription,UserSQL FROM UserSQLStatements "
strSQL &= "WHERE UserName <> '" & mdlGeneral.strUserName.Replace("'", "''").Trim() & "' AND PublicUse = 1"
da = New clsDataAccess
Dim ods As New DataSet
ods = da.Return_DataSet(strSQL)
If ods IsNot Nothing Then
Me.dgPuiblicStatements.DataSource = Nothing
Me.dgUserStatements.DataSource = Nothing
Me.dgUserStatements.DataSource = ods.Tables(0)
Me.dgPuiblicStatements.DataSource = ods.Tables(1)
Me.dgPuiblicStatements.Columns(0).Visible = False
Me.dgPuiblicStatements.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
Me.dgPuiblicStatements.Columns(2).Width = 600
Me.dgPuiblicStatements.Columns(3).Width = 600
Me.dgUserStatements.Columns(0).Visible = False
Me.dgUserStatements.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
Me.dgUserStatements.Columns(2).Width = 600
Me.dgUserStatements.Columns(3).Width = 600
ods.Dispose()
End If
da.Dispose()
If mdlGeneral.errMessage.intErrNum <> 0 Then
MessageBox.Show("Error retrieving SQL Statements from the database.", "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
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.
Re: Scroll bar for DataGridView
No difference just now can't see the last column since the one before is to large.
1 Attachment(s)
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
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.
Re: Scroll bar for DataGridView
Thanks Matt this is solved. I never look at the size.
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.
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.