G
Guest
When we updated the Framework to SP1 a strange thing happened to our
datagrids. If a cell was selected and the underlying datasource changed. The
selected cell would not refresh to the correct value. If there was no row on
that part of the datagrid, you would still see the old value. It would look
like a ghost cell in the middle of the grid!! I positive it's because of SP1,
only machines in our plant with SP1 are affected. Bellow I have code that
will reproduce the problem.
Run the application.
Click on any cell (except the first row) to highlight the text.
Click the filter button.
The cell that you highlighted should still be there.
I did find that it has something to do with the GridColumnStyle. If it's set
to readonly then the problem occurs. If it's not set to read only then
everything is all right.
--
Thanks in advance.
KeithH
*******************************
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 DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents DataGridTableStyle1 As
System.Windows.Forms.DataGridTableStyle
Friend WithEvents DataGridTextBoxColumn1 As
System.Windows.Forms.DataGridTextBoxColumn
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.DataGridTableStyle1 = New System.Windows.Forms.DataGridTableStyle
Me.DataGridTextBoxColumn1 = New
System.Windows.Forms.DataGridTextBoxColumn
Me.Button1 = New System.Windows.Forms.Button
CType(Me.DataGrid1,
System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(16, 16)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.ReadOnly = True
Me.DataGrid1.Size = New System.Drawing.Size(264, 240)
Me.DataGrid1.TabIndex = 0
Me.DataGrid1.TableStyles.AddRange(New
System.Windows.Forms.DataGridTableStyle() {Me.DataGridTableStyle1})
'
'DataGridTableStyle1
'
Me.DataGridTableStyle1.AlternatingBackColor =
System.Drawing.Color.LightYellow()
Me.DataGridTableStyle1.BackColor = System.Drawing.Color.White
Me.DataGridTableStyle1.DataGrid = Me.DataGrid1
Me.DataGridTableStyle1.ForeColor = System.Drawing.Color.Black
Me.DataGridTableStyle1.GridColumnStyles.AddRange(New
System.Windows.Forms.DataGridColumnStyle() {Me.DataGridTextBoxColumn1})
Me.DataGridTableStyle1.GridLineColor =
System.Drawing.Color.LightSteelBlue()
Me.DataGridTableStyle1.HeaderBackColor =
System.Drawing.Color.RoyalBlue()
Me.DataGridTableStyle1.HeaderForeColor = System.Drawing.Color.White
Me.DataGridTableStyle1.LinkColor = System.Drawing.Color.Magenta
Me.DataGridTableStyle1.MappingName = "Table1"
Me.DataGridTableStyle1.ReadOnly = True
Me.DataGridTableStyle1.SelectionBackColor =
System.Drawing.Color.DodgerBlue()
Me.DataGridTableStyle1.SelectionForeColor = System.Drawing.Color.White
'
'DataGridTextBoxColumn1
'
Me.DataGridTextBoxColumn1.Format = ""
Me.DataGridTextBoxColumn1.FormatInfo = Nothing
Me.DataGridTextBoxColumn1.HeaderText = "Column1"
Me.DataGridTextBoxColumn1.MappingName = "Column1"
Me.DataGridTextBoxColumn1.ReadOnly = True
Me.DataGridTextBoxColumn1.Width = 75
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(16, 264)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(64, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Filter"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 310)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.DataGrid1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataGrid1,
System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private ds As New DataSet
Private IsFiltered As Boolean = False
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
FillDataSources()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If IsFiltered Then
ds.Tables("Table1").DefaultView.RowFilter = ""
IsFiltered = False
Else
ds.Tables("Table1").DefaultView.RowFilter = "Column1='Text 1'"
IsFiltered = True
End If
End Sub
Private Sub FillDataSources()
Dim dt As DataTable
Dim dr As DataRow
Dim index As Integer
dt = ds.Tables.Add("Table1")
dt.Columns.Add("Column1")
For index = 1 To 5
dr = dt.NewRow()
dr("Column1") = "Text " & CStr(index)
dt.Rows.Add(dr)
Next
DataGrid1.SetDataBinding(ds.Tables("Table1").DefaultView, "")
End Sub
End Class
***********************
datagrids. If a cell was selected and the underlying datasource changed. The
selected cell would not refresh to the correct value. If there was no row on
that part of the datagrid, you would still see the old value. It would look
like a ghost cell in the middle of the grid!! I positive it's because of SP1,
only machines in our plant with SP1 are affected. Bellow I have code that
will reproduce the problem.
Run the application.
Click on any cell (except the first row) to highlight the text.
Click the filter button.
The cell that you highlighted should still be there.
I did find that it has something to do with the GridColumnStyle. If it's set
to readonly then the problem occurs. If it's not set to read only then
everything is all right.
--
Thanks in advance.
KeithH
*******************************
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 DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents DataGridTableStyle1 As
System.Windows.Forms.DataGridTableStyle
Friend WithEvents DataGridTextBoxColumn1 As
System.Windows.Forms.DataGridTextBoxColumn
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.DataGridTableStyle1 = New System.Windows.Forms.DataGridTableStyle
Me.DataGridTextBoxColumn1 = New
System.Windows.Forms.DataGridTextBoxColumn
Me.Button1 = New System.Windows.Forms.Button
CType(Me.DataGrid1,
System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(16, 16)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.ReadOnly = True
Me.DataGrid1.Size = New System.Drawing.Size(264, 240)
Me.DataGrid1.TabIndex = 0
Me.DataGrid1.TableStyles.AddRange(New
System.Windows.Forms.DataGridTableStyle() {Me.DataGridTableStyle1})
'
'DataGridTableStyle1
'
Me.DataGridTableStyle1.AlternatingBackColor =
System.Drawing.Color.LightYellow()
Me.DataGridTableStyle1.BackColor = System.Drawing.Color.White
Me.DataGridTableStyle1.DataGrid = Me.DataGrid1
Me.DataGridTableStyle1.ForeColor = System.Drawing.Color.Black
Me.DataGridTableStyle1.GridColumnStyles.AddRange(New
System.Windows.Forms.DataGridColumnStyle() {Me.DataGridTextBoxColumn1})
Me.DataGridTableStyle1.GridLineColor =
System.Drawing.Color.LightSteelBlue()
Me.DataGridTableStyle1.HeaderBackColor =
System.Drawing.Color.RoyalBlue()
Me.DataGridTableStyle1.HeaderForeColor = System.Drawing.Color.White
Me.DataGridTableStyle1.LinkColor = System.Drawing.Color.Magenta
Me.DataGridTableStyle1.MappingName = "Table1"
Me.DataGridTableStyle1.ReadOnly = True
Me.DataGridTableStyle1.SelectionBackColor =
System.Drawing.Color.DodgerBlue()
Me.DataGridTableStyle1.SelectionForeColor = System.Drawing.Color.White
'
'DataGridTextBoxColumn1
'
Me.DataGridTextBoxColumn1.Format = ""
Me.DataGridTextBoxColumn1.FormatInfo = Nothing
Me.DataGridTextBoxColumn1.HeaderText = "Column1"
Me.DataGridTextBoxColumn1.MappingName = "Column1"
Me.DataGridTextBoxColumn1.ReadOnly = True
Me.DataGridTextBoxColumn1.Width = 75
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(16, 264)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(64, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Filter"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 310)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.DataGrid1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataGrid1,
System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private ds As New DataSet
Private IsFiltered As Boolean = False
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
FillDataSources()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If IsFiltered Then
ds.Tables("Table1").DefaultView.RowFilter = ""
IsFiltered = False
Else
ds.Tables("Table1").DefaultView.RowFilter = "Column1='Text 1'"
IsFiltered = True
End If
End Sub
Private Sub FillDataSources()
Dim dt As DataTable
Dim dr As DataRow
Dim index As Integer
dt = ds.Tables.Add("Table1")
dt.Columns.Add("Column1")
For index = 1 To 5
dr = dt.NewRow()
dr("Column1") = "Text " & CStr(index)
dt.Rows.Add(dr)
Next
DataGrid1.SetDataBinding(ds.Tables("Table1").DefaultView, "")
End Sub
End Class
***********************