472,811 Members | 1,321 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,811 software developers and data experts.

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 1791
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Terry | last post by:
Hey, Having somewhat of an issue, I have a datagrid which is giving me issues. The Datagrid is setup for the user to double click the row, the row is selected and data within that row populates a...
3
by: suresh | last post by:
frenz, i need to disable the add new record mode in datarid. i just want to modify the existing records in the grid...but i dont want to add new records..how do i do that? -suresh
2
by: Agnes | last post by:
In myDatagrid, there is 3 columns, account code, debit,credit. If the user input some particular a account code in column1 , i need to based on the contect of column1, to disable...
1
by: Geroge D. Lake | last post by:
Hi, I need to disable the resizing of a datagrid. I have tried al day and no luck. Any Ideas? Thanks. George.
2
by: PAUL GROSSMAN | last post by:
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 ...
1
by: johnb41 | last post by:
I have a datagrid that successfully allows editing and updating (with dataadapter.update command). I want the user to be able to edit the "text" in the datagrid, but i DON'T want the user to be...
8
by: simchajoy2000 | last post by:
I thought the only thing I had to do to disable column sorting in VB.NET was to set datagrid.AllowSorting = False. Unfortunately this has never worked for me. I discovered another set of code...
2
by: Mike | last post by:
Hi, I would like to disable sorting in a winform datagrid when a column header is clicked. The following does *not* seem to disable sorting and clicking the column header still sorts the grid:...
1
by: ECD | last post by:
Hello all, I can usually find solutions to my .NET problems by searching these groups, but I'm stumped on this one. I have a datagrid in VB.NET (2.0 framework). I want to disable sorting on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.