Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2005

Tip: Looking for answers? Try searching our database.

no active cell in read-only datagrid

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Don - 31 Jan 2005 17:25 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.