E
eBob.com
I have a nearly empty form. In the designer I set Autoscroll to True. At
run time I dynamically add a DataGridView which is larger than the form.
That should result in Form scroll bars (the DataGridView is larger than the
form) but does not. Unless I squeeze the form down to a really small size.
All of many attempts to reproduce the problem in a really simple program
have failed. But the code that fails is fairly brief and simple. So I have
included it below and hope that someone who is bored today might take a look
and see if they spot anything, or maybe even try it.
In the designer I create a button named btnSpecifyFolder (drive/folder info
is used to populate the DataGridView), a FolderBrowserDiaglog (default name)
and set the form AutoScroll to True. I also set the size of the form so
that once the
DataGridView is added the scroll bars will be required.
Thanks for any help you can give me. Code's below. Bob
Option Strict On
Option Explicit On
Imports System.IO
Imports System.ComponentModel
Public Class Form1
Class MasterDGVRowTag ' used for rows in the MasterDGV
End Class
Dim DriveFolder As String
Dim di As DirectoryInfo
Dim MasterDGV As DataGridView
Dim diArray As DirectoryInfo()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnSpecifyFolder_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnSpecifyFolder.Click
Dim FBDresult As Integer = FolderBrowserDialog1.ShowDialog()
If FBDresult = DialogResult.OK Then
DriveFolder = FolderBrowserDialog1.SelectedPath
'MsgBox("selectedpath is """ & DriveFolder & """")
di = New DirectoryInfo(DriveFolder)
End If
diArray = di.GetDirectories
CreateMasterDGV() ' go create and populate the MasterDGV
Me.Controls.Add(MasterDGV)
End Sub
Sub CreateMasterDGV()
'
' create empty DGV
'
MasterDGV = New DataGridView
With MasterDGV
.Anchor = DirectCast(AnchorStyles.Bottom + AnchorStyles.Left +
AnchorStyles.Right + AnchorStyles.Top, AnchorStyles)
End With
SetupMasterDGV(MasterDGV)
AddHandler MasterDGV.CellMouseClick, AddressOf
MasterDGV_CellMouseClick
'
' now populate the MasterDGV
'
For Each directory As DirectoryInfo In diArray
Try
AddRow2(directory.Name, directory.LastAccessTime,
directory.CreationTime, directory.LastWriteTime)
Catch
End Try
Next
MasterDGV.Height = MasterDGV.Rows.Item(0).Height *
MasterDGV.Rows.Count _
+ MasterDGV.ColumnHeadersHeight ' set height of Master seg.
we've been working on
End Sub
Sub AddRow2(ByRef dirname As String, _
ByRef lat As Date, ByRef law As Date, ByRef cd As Date)
Dim AddedRowIndex As Integer
Dim dgvr As New DataGridViewRow
dgvr.CreateCells(MasterDGV)
dgvr.Cells(0).Value = "+"
dgvr.Cells(1).Value = dirname
'dgvr.Cells(2).Value = filename
dgvr.Cells(3).Value = lat
dgvr.Cells(4).Value = cd
dgvr.Cells(5).Value = law
'dgvr.Cells(6).Value = length
AddedRowIndex = MasterDGV.Rows.Add(dgvr) ' add row, get newly added
row's index
'MasterDGV.Rows.Item(AddedRowIndex).Tag = New MasterDGVRowTag(True,
False)
MasterDGV(1, 1).ToolTipText = "detail data"
End Sub 'AddRow2
Private Sub MasterDGV_CellMouseClick(ByVal sender As Object, ByVal e As
DataGridViewCellMouseEventArgs)
If e.RowIndex = -1 Then Exit Sub ' ignore clicks in header row
End Sub
Sub SetupMasterDGV(ByVal dgv As DataGridView)
' the Height is not set here as that has to be set after it is
populated
dgv.ColumnCount = 7
With dgv
.Location = New Point(0, 40)
.AllowUserToOrderColumns = False ' because this doesn't work
when the master table is segmented
.Width = 500
.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
With .ColumnHeadersDefaultCellStyle
.BackColor = Color.Navy
.ForeColor = Color.White
.Font = New Font(MasterDGV.Font, FontStyle.Bold)
End With
.CellBorderStyle = DataGridViewCellBorderStyle.Single
.GridColor = Color.Black
.RowHeadersVisible = False
.ScrollBars = ScrollBars.Horizontal
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False
.AllowUserToOrderColumns = True
.ReadOnly = True
With .Columns(0)
.Width = 20
.ValueType = GetType(String)
End With
With .Columns(1)
.Name = "Directory"
.ValueType = GetType(String)
.Width = 200
End With
With .Columns(2)
.Name = "FileName"
.ValueType = GetType(String)
End With
With .Columns(3)
.Name = "Last Accessed"
.ValueType = GetType(Date)
.Width = 150
End With
With .Columns(4)
.Name = "Create Date"
.ValueType = GetType(Date)
.Width = 150
.Visible = False
End With
With .Columns(5)
.Name = "Last Written"
.ValueType = GetType(Date)
.Width = 150
.Visible = False
End With
With .Columns(6)
.Name = "Size"
.ValueType = GetType(Long)
.DefaultCellStyle.Format = "n0"
.HeaderCell.Style.Alignment =
DataGridViewContentAlignment.MiddleRight
.DefaultCellStyle.Alignment =
DataGridViewContentAlignment.MiddleRight
End With
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.MultiSelect = False
End With
End Sub 'SetupMasterDGV
End Class
run time I dynamically add a DataGridView which is larger than the form.
That should result in Form scroll bars (the DataGridView is larger than the
form) but does not. Unless I squeeze the form down to a really small size.
All of many attempts to reproduce the problem in a really simple program
have failed. But the code that fails is fairly brief and simple. So I have
included it below and hope that someone who is bored today might take a look
and see if they spot anything, or maybe even try it.
In the designer I create a button named btnSpecifyFolder (drive/folder info
is used to populate the DataGridView), a FolderBrowserDiaglog (default name)
and set the form AutoScroll to True. I also set the size of the form so
that once the
DataGridView is added the scroll bars will be required.
Thanks for any help you can give me. Code's below. Bob
Option Strict On
Option Explicit On
Imports System.IO
Imports System.ComponentModel
Public Class Form1
Class MasterDGVRowTag ' used for rows in the MasterDGV
End Class
Dim DriveFolder As String
Dim di As DirectoryInfo
Dim MasterDGV As DataGridView
Dim diArray As DirectoryInfo()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnSpecifyFolder_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnSpecifyFolder.Click
Dim FBDresult As Integer = FolderBrowserDialog1.ShowDialog()
If FBDresult = DialogResult.OK Then
DriveFolder = FolderBrowserDialog1.SelectedPath
'MsgBox("selectedpath is """ & DriveFolder & """")
di = New DirectoryInfo(DriveFolder)
End If
diArray = di.GetDirectories
CreateMasterDGV() ' go create and populate the MasterDGV
Me.Controls.Add(MasterDGV)
End Sub
Sub CreateMasterDGV()
'
' create empty DGV
'
MasterDGV = New DataGridView
With MasterDGV
.Anchor = DirectCast(AnchorStyles.Bottom + AnchorStyles.Left +
AnchorStyles.Right + AnchorStyles.Top, AnchorStyles)
End With
SetupMasterDGV(MasterDGV)
AddHandler MasterDGV.CellMouseClick, AddressOf
MasterDGV_CellMouseClick
'
' now populate the MasterDGV
'
For Each directory As DirectoryInfo In diArray
Try
AddRow2(directory.Name, directory.LastAccessTime,
directory.CreationTime, directory.LastWriteTime)
Catch
End Try
Next
MasterDGV.Height = MasterDGV.Rows.Item(0).Height *
MasterDGV.Rows.Count _
+ MasterDGV.ColumnHeadersHeight ' set height of Master seg.
we've been working on
End Sub
Sub AddRow2(ByRef dirname As String, _
ByRef lat As Date, ByRef law As Date, ByRef cd As Date)
Dim AddedRowIndex As Integer
Dim dgvr As New DataGridViewRow
dgvr.CreateCells(MasterDGV)
dgvr.Cells(0).Value = "+"
dgvr.Cells(1).Value = dirname
'dgvr.Cells(2).Value = filename
dgvr.Cells(3).Value = lat
dgvr.Cells(4).Value = cd
dgvr.Cells(5).Value = law
'dgvr.Cells(6).Value = length
AddedRowIndex = MasterDGV.Rows.Add(dgvr) ' add row, get newly added
row's index
'MasterDGV.Rows.Item(AddedRowIndex).Tag = New MasterDGVRowTag(True,
False)
MasterDGV(1, 1).ToolTipText = "detail data"
End Sub 'AddRow2
Private Sub MasterDGV_CellMouseClick(ByVal sender As Object, ByVal e As
DataGridViewCellMouseEventArgs)
If e.RowIndex = -1 Then Exit Sub ' ignore clicks in header row
End Sub
Sub SetupMasterDGV(ByVal dgv As DataGridView)
' the Height is not set here as that has to be set after it is
populated
dgv.ColumnCount = 7
With dgv
.Location = New Point(0, 40)
.AllowUserToOrderColumns = False ' because this doesn't work
when the master table is segmented
.Width = 500
.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
With .ColumnHeadersDefaultCellStyle
.BackColor = Color.Navy
.ForeColor = Color.White
.Font = New Font(MasterDGV.Font, FontStyle.Bold)
End With
.CellBorderStyle = DataGridViewCellBorderStyle.Single
.GridColor = Color.Black
.RowHeadersVisible = False
.ScrollBars = ScrollBars.Horizontal
.AllowUserToAddRows = False
.AllowUserToDeleteRows = False
.AllowUserToOrderColumns = True
.ReadOnly = True
With .Columns(0)
.Width = 20
.ValueType = GetType(String)
End With
With .Columns(1)
.Name = "Directory"
.ValueType = GetType(String)
.Width = 200
End With
With .Columns(2)
.Name = "FileName"
.ValueType = GetType(String)
End With
With .Columns(3)
.Name = "Last Accessed"
.ValueType = GetType(Date)
.Width = 150
End With
With .Columns(4)
.Name = "Create Date"
.ValueType = GetType(Date)
.Width = 150
.Visible = False
End With
With .Columns(5)
.Name = "Last Written"
.ValueType = GetType(Date)
.Width = 150
.Visible = False
End With
With .Columns(6)
.Name = "Size"
.ValueType = GetType(Long)
.DefaultCellStyle.Format = "n0"
.HeaderCell.Style.Alignment =
DataGridViewContentAlignment.MiddleRight
.DefaultCellStyle.Alignment =
DataGridViewContentAlignment.MiddleRight
End With
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.MultiSelect = False
End With
End Sub 'SetupMasterDGV
End Class