Re: No Tab Stop DataGridView Column
- From: "Larry Smith" <no_spam@xxxxxxxxxxx>
- Date: Fri, 20 Apr 2007 08:40:50 -0400
"Richard MSL" <RichardKirkness@xxxxxxxxxxxxx> wrote in message
news:D8581263-FF62-40BD-898A-F9F1248A7B00@xxxxxxxxxxxxxxxx
I have a DataGridView control with some regular columns, and some columns
that are just for display, populated by my program. The user is not
supposed
to be able to change the data in these columns, or even tab or mouse to
them.
I can set the column ReadOnly property, but the tab and mouse still allow
that column to be selected.
Is there a way to make the column just display, without being able to tab
or
mouse to it? When the user tabbed from the column on the left, I want it
to
just skip over the display column, directly to the next editable column.
Thanks.
You would think that such a common requirement would be natively available
but it's not. You have to roll it yourself and it's not trivial. For one
thing, the grid is buggy and will often result in various errors if you try
to change the target cell from within different "DataGridView" event
handlers (when you trying to modifyc the "CurrentCell" property typically).
The following is the most common:
"Operation is not valid because it results in a reentrant call to the
SetCurrentCellAddressCore function"
I saw at least one posting elsewhere where Mark Rideout confirms this
problem under some another circumstance. He's the guy who manages this
control at MSFT. The only way I've been able to find to circumvent this
problem (after much pain) was to provide a "DataGridView" derivative. You
then have to override "SetCurrentCellAddressCore()" and
"SetSelectedCellCore()" and change the "columnIndex" parameter (and/or
"rowIndex") before invoking the base class version. You may also have to
implement an "OnKeyDown()" override as well. For instance, in my case, the
left-hand column is always off-limits to the user. If they click it then the
first two functions mentioned above will automatically move them to the
adjacent cell on the right. If they then <Shift-Tab> from the latter column
however then my "OnKeyDown()" override traps it and sets "CurrentCell" to
the right-most column on the previous visible row (assuming they're not on
the first visible row in the grid at the time - make sure you're handling
*visible* rows when you do this, assuming your grid contains hidden rows
either now or in the future). You'll have to experiment to get everything
right of course and cope with the frustration along the way. Good luck.
.
- Prev by Date: Re: Using CreateDesktop User32.dll method
- Next by Date: RE: No Tab Stop DataGridView Column
- Previous by thread: Microsoft.Reporting.WinForms.ReportViewer in ProcessingMode.Local
- Next by thread: Re: No Tab Stop DataGridView Column
- Index(es):
Relevant Pages
|
|