No active cell in read-only datagrid

D

Don

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
 
D

Don

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top