PC Review


Reply
Thread Tools Rate Thread

Can you Disable a DataGrid column?

 
 
PAUL GROSSMAN
Guest
Posts: n/a
 
      19th Feb 2005
Hello everyone.


I am working with a DataGrid using VB .Net (Windows Forms). I want to
make one of the columns un-editable. I was able to do that by setting
the .dsName.Tables("TblName").Columns("ColName").ReadOnly = True


That made it so you can't change the value in the column, but you're
still tabbing into the column (despite the fact you can't change it).


How can I make it so that you can both be unable to change the value in
a datagrid column and also not be able to tab into the column?


Thank you very much in advance for your help.
Paul.



 
Reply With Quote
 
 
 
 
Derek Harmon
Guest
Posts: n/a
 
      19th Feb 2005
"PAUL GROSSMAN" <(E-Mail Removed)> wrote in message news:CJzRd.25101$ya6.12064@trndny01...
> I want to make one of the columns un-editable. I was able to do that by setting
> the .dsName.Tables("TblName").Columns("ColName").ReadOnly = True


Paul,

I think I hear that you're saying you set ReadOnly on the DataColumn. Have
you tried setting ReadOnly on the DataGridColumnStyle?

Me.dataGrid1.TableStyles("TblName").GridColumnStyles("ColName").ReadOnly = True

The DataColumn represents the "model" of the data, whereas the DataGrid-
ColumnStyle represents the "view" of that data. It might be more on-target
to modify the view's characteristics instead of the model's.

Another thing you might try is to handle the CurrentCellChanged event
to check Me.dataGrid1.CurrentCell.ColumnNumber and change it back
whenever the end user selects a column you don't wish to receive focus.

> That made it so you can't change the value in the column, but you're
> still tabbing into the column (despite the fact you can't change it).


As an aside, if you're writing an application that needs to be Accessible
then the effect of a user's TAB key shifting focus to a non-editable cell
isn't necessarily a bad thing. Some screen readers (for the blind) use
speech-synthesis to recite the contents of cells that receive focus. If
you must workaround this problem, it may limit the application's
Accessibility.


Derek Harmon


 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      19th Feb 2005
Hi Derek,

Thank you for that great advice. It works !

Your suggestion to check the currentCellChanged event worked great. Also, I
applied the same code to the GotFocus event in the case when you click on
the DataGrid for the first time.

Here's the code I used:
Dim vCurRow As Integer = DataGrid.CurrentCell.RowNumber
DataGrid.CurrentCell = New DataGridCell(vCurRow, 1)



However - I have a "New" problem, and I can't seem to find the solution no
matter how bad I bang my head over here...

When I try to backTab, it doesn't go to the previous row. Now I know that I
would have to check for the BackTab key and apply the same logic above
except the row could be the vCurRow - 1.

But... I tried using KeyPress, and KeyDown events and I can't trap the
BackTab key.

Would anyone have any suggestions as to how I can trap the BackTab Key

(I checked the VS help and it says to do this :
"Certain keys, such as the TAB, RETURN, ESCAPE, and arrow keys are handled
by controls automatically. In order to have these keys raise the KeyDown
event, you must override the IsInputKey method in each control on your form.
The code for the override of the IsInputKey would need to determine if one
of the special keys is pressed and return a value of true. ")

I am wondering if there's an easier way to trap the BackTab key than what's
shown in the help.

Again your help is greatly appreciated.
Thank you,

Paul.



"Derek Harmon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "PAUL GROSSMAN" <(E-Mail Removed)> wrote in message
> news:CJzRd.25101$ya6.12064@trndny01...
>> I want to make one of the columns un-editable. I was able to do that by
>> setting
>> the .dsName.Tables("TblName").Columns("ColName").ReadOnly = True

>
> Paul,
>
> I think I hear that you're saying you set ReadOnly on the DataColumn.
> Have
> you tried setting ReadOnly on the DataGridColumnStyle?
>
>
> Me.dataGrid1.TableStyles("TblName").GridColumnStyles("ColName").ReadOnly =
> True
>
> The DataColumn represents the "model" of the data, whereas the DataGrid-
> ColumnStyle represents the "view" of that data. It might be more
> on-target
> to modify the view's characteristics instead of the model's.
>
> Another thing you might try is to handle the CurrentCellChanged event
> to check Me.dataGrid1.CurrentCell.ColumnNumber and change it back
> whenever the end user selects a column you don't wish to receive focus.
>
>> That made it so you can't change the value in the column, but you're
>> still tabbing into the column (despite the fact you can't change it).

>
> As an aside, if you're writing an application that needs to be Accessible
> then the effect of a user's TAB key shifting focus to a non-editable cell
> isn't necessarily a bad thing. Some screen readers (for the blind) use
> speech-synthesis to recite the contents of cells that receive focus. If
> you must workaround this problem, it may limit the application's
> Accessibility.
>
>
> Derek Harmon
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Any way to disable a column in a DataGrid? Rico Microsoft ASP .NET 5 23rd Mar 2006 11:23 PM
Any way to disable a column in a DataGrid? Rico Microsoft Dot NET 7 23rd Mar 2006 11:23 PM
Any way to disable a column in a DataGrid? Rico Microsoft VB .NET 5 23rd Mar 2006 11:23 PM
Can you Disable a DataGrid column? PAUL GROSSMAN Microsoft VB .NET 2 19th Feb 2005 06:25 AM
datagrid disable column kuvpatel Microsoft C# .NET 1 17th Oct 2003 02:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:25 AM.