473,385 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 1828
"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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.