bob01900 Posted July 7, 2003 Posted July 7, 2003 I have got one datagrid inside each TabControl page, and I have them docked or anchored so they will resize according to the form's size. If I shrink the form's size small enough so that for each page, I can see the scroll bar(s). After going through each tab page and have seen the scroll bars on each page (problem only happen if I do this), I then maximise the form so that I can see the scroll bars on the "current" tab page disappearing. This is where the problem starts. After maximising, other tab pages' scroll bars will remain in the same position as before, even though the datagrid has expanded. So I will have the scroll bars (at the position before maximising) overlapping on the datagrid (which expanded). Please note that I did NOT write any code for scroll bars (from datagrid). They justs appear automatically if the form/control size is too small. I have tried update() and refresh() for both tabpages and datagrid, but nothing seem to be able to get rid of those scroll bars. But they do disappear as soon as I resize. Just wondering if anyone else has seen this kind of problem before? Thank you for your help. Quote
bob01900 Posted July 7, 2003 Author Posted July 7, 2003 Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents TabControl1 As System.Windows.Forms.TabControl Friend WithEvents TabPage1 As System.Windows.Forms.TabPage Friend WithEvents TabPage2 As System.Windows.Forms.TabPage Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid Friend WithEvents DataGrid2 As System.Windows.Forms.DataGrid Friend WithEvents DataSet1 As System.Data.DataSet Friend WithEvents DataTable1 As System.Data.DataTable Friend WithEvents DataTable2 As System.Data.DataTable Friend WithEvents DataColumn1 As System.Data.DataColumn Friend WithEvents DataColumn2 As System.Data.DataColumn <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.TabControl1 = New System.Windows.Forms.TabControl() Me.TabPage1 = New System.Windows.Forms.TabPage() Me.DataGrid1 = New System.Windows.Forms.DataGrid() Me.TabPage2 = New System.Windows.Forms.TabPage() Me.DataGrid2 = New System.Windows.Forms.DataGrid() Me.DataSet1 = New System.Data.DataSet() Me.DataTable1 = New System.Data.DataTable() Me.DataColumn1 = New System.Data.DataColumn() Me.DataTable2 = New System.Data.DataTable() Me.DataColumn2 = New System.Data.DataColumn() Me.TabControl1.SuspendLayout() Me.TabPage1.SuspendLayout() CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit() Me.TabPage2.SuspendLayout() CType(Me.DataGrid2, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.DataSet1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.DataTable1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.DataTable2, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'TabControl1 ' Me.TabControl1.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _ Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right) Me.TabControl1.Controls.AddRange(New System.Windows.Forms.Control() {Me.TabPage1, Me.TabPage2}) Me.TabControl1.Location = New System.Drawing.Point(16, 16) Me.TabControl1.Name = "TabControl1" Me.TabControl1.SelectedIndex = 0 Me.TabControl1.Size = New System.Drawing.Size(472, 336) Me.TabControl1.TabIndex = 0 ' 'TabPage1 ' Me.TabPage1.Controls.AddRange(New System.Windows.Forms.Control() {Me.DataGrid1}) Me.TabPage1.Location = New System.Drawing.Point(4, 22) Me.TabPage1.Name = "TabPage1" Me.TabPage1.Size = New System.Drawing.Size(464, 310) Me.TabPage1.TabIndex = 0 Me.TabPage1.Text = "TabPage1" ' 'DataGrid1 ' Me.DataGrid1.DataMember = "" Me.DataGrid1.DataSource = Me.DataTable1 Me.DataGrid1.Dock = System.Windows.Forms.DockStyle.Fill Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText Me.DataGrid1.Name = "DataGrid1" Me.DataGrid1.ReadOnly = True Me.DataGrid1.Size = New System.Drawing.Size(464, 310) Me.DataGrid1.TabIndex = 0 ' 'TabPage2 ' Me.TabPage2.Controls.AddRange(New System.Windows.Forms.Control() {Me.DataGrid2}) Me.TabPage2.Location = New System.Drawing.Point(4, 22) Me.TabPage2.Name = "TabPage2" Me.TabPage2.Size = New System.Drawing.Size(464, 310) Me.TabPage2.TabIndex = 1 Me.TabPage2.Text = "TabPage2" ' 'DataGrid2 ' Me.DataGrid2.DataMember = "" Me.DataGrid2.DataSource = Me.DataTable2 Me.DataGrid2.Dock = System.Windows.Forms.DockStyle.Fill Me.DataGrid2.HeaderForeColor = System.Drawing.SystemColors.ControlText Me.DataGrid2.Name = "DataGrid2" Me.DataGrid2.ReadOnly = True Me.DataGrid2.Size = New System.Drawing.Size(464, 310) Me.DataGrid2.TabIndex = 0 ' 'DataSet1 ' Me.DataSet1.DataSetName = "NewDataSet" Me.DataSet1.Locale = New System.Globalization.CultureInfo("en-NZ") Me.DataSet1.Tables.AddRange(New System.Data.DataTable() {Me.DataTable1, Me.DataTable2}) ' 'DataTable1 ' Me.DataTable1.Columns.AddRange(New System.Data.DataColumn() {Me.DataColumn1}) Me.DataTable1.TableName = "Table1" ' 'DataColumn1 ' Me.DataColumn1.ColumnName = "Column1" ' 'DataTable2 ' Me.DataTable2.Columns.AddRange(New System.Data.DataColumn() {Me.DataColumn2}) Me.DataTable2.TableName = "Table2" ' 'DataColumn2 ' Me.DataColumn2.ColumnName = "Column1" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(504, 366) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TabControl1}) Me.Name = "Form1" Me.Text = "Form1" Me.TabControl1.ResumeLayout(False) Me.TabPage1.ResumeLayout(False) CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit() Me.TabPage2.ResumeLayout(False) CType(Me.DataGrid2, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.DataSet1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.DataTable1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.DataTable2, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim i As Integer For i = 0 To 20 DataTable1.Rows.Add(New Object() {"Row " & CStr(i)}) DataTable2.Rows.Add(New Object() {"Row " & CStr(i)}) Next End Sub End Class '''''''''''''''''''''''''''''''''''''''''''' Here is a simple example of what I am talking about. Compile this, and run the program. Then 1. Click on TabPage2 2. Maximise 3. Click on TabPage1 4. You should see the datagrid of TabPage1 still has that scroll bar PS. Assuming you are using 1024x768 or greater resolution Quote
nirubhai Posted June 17, 2005 Posted June 17, 2005 (edited) try this one i had same problem. try something like this, it worked for me. call it in tab resize or click. Dim hs As HScrollBar Dim vs As VScrollBar For Each c As Control In DataGrid1.Controls If c.GetType() Is GetType(VScrollBar) Then vs = CType(c, VScrollBar) vs.Left = DataGrid1.Width - vs.Width End If If c.GetType() Is GetType(HScrollBar) Then hs = CType(c, HScrollBar) hs.Top = DataGrid1.Height - hs.Height End If Next DataGrid1.Refresh() though the post is old, someone else might need it :) Edited June 17, 2005 by nirubhai Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.