473,383 Members | 1,978 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,383 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.

Nov 21 '05 #1
2 10448
"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
Nov 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

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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 ...
4
by: Steve B. | last post by:
How do I find the column (index) number at runtime of a particular DataGrid column if I know the column header string //somthing like the following int x = datagrid.column;
1
by: Adil Bohoudi | last post by:
Hi all, i'm using a datagrid to show somedata retrieved from an sql-server 2000. this datagrid contains two columns a startdate and an enddate column. i used a storedprocedure to get both...
9
by: Roy | last post by:
Hey all, On my html page I have a datagrid with the column: <boundColumn datafield="xyz" visible = false> </boundColumn> In my code behind, within item data bound event, I dynamically set the...
1
by: ElenaR | last post by:
I need to figure out how to name my column headers in a DataGrid. In VB6, I could write DataGrid1.Columns(0).Caption = "ID". What is the format for VB.NET? Thanks in Advance!
6
by: Aaron Smith | last post by:
Is there a way to put a limit on the text size of a datagrid column? Thanks, Aaron -- --- Aaron Smith Remove -1- to E-Mail me. Spam Sucks.
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: Starbuck | last post by:
Hi Is there anyway of capturing when the users adjusts the width of a datagrid column so the new column width can be stored. Thanks in advance
1
by: Veeves | last post by:
I would like to change the width of a datagrid column at run time. I have noticed when creating a datagrid, if the header text is shorter than the data in the column, then the column width set by...
4
by: gane | last post by:
Hi, I am creating datagrid bound column dynamically and need to check if a datagrid column already exists?Is there a way to check this? thanks gane
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.