George Shepherd's great Windows Forms FAQ has this article about creating a
datagrid with no active cell:
http://www.syncfusion.com/faq/winforms/search/856.asp
Unfortunately, this only works properly for datagrids that are not ReadOnly
(i.e. a row will become unhighlighted if you click the same cell twice).
Has anyone discovered a way to have a read-only datagrid with no active
cell?
- Don
Don - 31 Jan 2005 17:51 GMT
My own solution to this problem was to use George Shepherd's solution, but
use it with an extended datagrid. My new datagrid looks like this:
Public Class DataGridEx
Inherits DataGrid
Protected Overrides Sub OnDataSourceChanged(ByVal e As System.EventArgs)
MyBase.OnDataSourceChanged(e)
' This prevents the 'add new' row from ever appearing! woohoo!
Try
Dim cm As CurrencyManager =
CType(Me.BindingContext(Me.DataSource, _
Me.DataMember), CurrencyManager)
CType(cm.List, DataView).AllowNew = False
Catch ex As Exception
Console.WriteLine("ERROR in DataGridEx.OnDataSourceChanged - " &
_
ex.Message)
End Try
End Sub
End Class
The code I put in the OnDataSourceChanged() method prevents the 'add new'
line from appearing in the datagrid. This way, I can leave the ReadOnly
property of the grid as "False" so that the "de-selection" bug with
Shepherd's solution doesn't occur. It seems to work fine for my purposes.
- Don