469,133 Members | 1,037 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,133 developers. It's quick & easy.

Can you Disable a DataGrid column?

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").ReadO nly = 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.

Jul 21 '05 #1
2 1686
"PAUL GROSSMAN" <pg********@verizon.net> 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").ReadO nly = 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").GridColumnStyl es("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
Jul 21 '05 #2
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" <lo*******@msn.com> wrote in message
news:uK**************@tk2msftngp13.phx.gbl...
"PAUL GROSSMAN" <pg********@verizon.net> 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").ReadO nly = 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").GridColumnStyl es("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

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Geroge D. Lake | last post: by
2 posts views Thread by PAUL GROSSMAN | last post: by
8 posts views Thread by simchajoy2000 | last post: by
2 posts views Thread by Mike | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.