473,320 Members | 1,974 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,320 software developers and data experts.

Avoid entering read-only column in DataGridView?

Column 0 in my unbound DataGridView is read-only. When the user tabs from the
last column of a row, I need the focus to go to column 1 of the next row, not
column 0.

Have tried a wide variety of events to accomplish this, but I always get:
"Operation is not valid because it results in a reentrant call to the
SetCurrentCellAddressCore function".

A simple example is:

private void dataGridItem_RowEnter(object sender, DataGridViewCellEventArgs e)
{
dataGridItem.CurrentCell =
dataGridItem.Rows[e.RowIndex].Cells[1];
}

Ignoring the error with Try/Catch almost works but not quite.

Would really appreciate any help.

Thanks

Bill.
Feb 2 '06 #1
7 2363
Hi Bill,

AFAIK, there is no properties that can be set in the DataGridView to
prevent a row from being selected. Here I'm handling the CellEnter event.
HTH.

private void dataGridView1_CellEnter(object sender,
DataGridViewCellEventArgs e)
{
try
{
if (e.ColumnIndex == 0)
this.dataGridView1.CurrentCell =
this.dataGridView1.Rows[e.RowIndex].Cells[1];
}
catch
{
}
}

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 3 '06 #2
Thanks Kevin. That almost works, in that the cell in the second column is
highlighted. However you can't type into that cell without first clicking on
the cell. That is a problem in my environment where high data volumes are
involved -- in this context users don't want to be slowed down by having to
pick up the mouse.

-- Bill.

Feb 6 '06 #3
Hi Bill,

As far as I can see, the performance is not slowed down by handling the
mouse events. Maybe this is the filling process that causes the performance
slowed down. In this case, you might re-consider the design of the app and
make it filling less records.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 7 '06 #4
Have you found a solution to this? I am trying to do the exact same thing
and got the same error. Selecting the next cell is not an option, the next
cell needs to have the focus and be editable.

"Bill" wrote:
Column 0 in my unbound DataGridView is read-only. When the user tabs from the
last column of a row, I need the focus to go to column 1 of the next row, not
column 0.

Have tried a wide variety of events to accomplish this, but I always get:
"Operation is not valid because it results in a reentrant call to the
SetCurrentCellAddressCore function".

A simple example is:

private void dataGridItem_RowEnter(object sender, DataGridViewCellEventArgs e)
{
dataGridItem.CurrentCell =
dataGridItem.Rows[e.RowIndex].Cells[1];
}

Ignoring the error with Try/Catch almost works but not quite.

Would really appreciate any help.

Thanks

Bill.

Feb 7 '06 #5

"Aspnot" wrote:
Have you found a solution to this? I am trying to do the exact same thing
and got the same error. Selecting the next cell is not an option, the next
cell needs to have the focus and be editable.


No I'm afraid I have found no solution.

Bill.
Feb 9 '06 #6
I came up with a solution. I'm not proud of it, but it works. I use the
following code in my CellEnter event.

Dim dgv As DataGridView = DirectCast(sender, DataGridView)

' Check for disabled. If so the force move to next control
If dgv.Rows(e.RowIndex).Cells(e.ColumnIndex).ReadOnly Then
SendKeys.Send("{TAB}")
End If

"Bill" wrote:

"Aspnot" wrote:
Have you found a solution to this? I am trying to do the exact same thing
and got the same error. Selecting the next cell is not an option, the next
cell needs to have the focus and be editable.


No I'm afraid I have found no solution.

Bill.

Feb 9 '06 #7
Works beautifully. Thanks so much Aspnot.

"Aspnot" wrote:
I came up with a solution. I'm not proud of it, but it works. I use the
following code in my CellEnter event.

Dim dgv As DataGridView = DirectCast(sender, DataGridView)

' Check for disabled. If so the force move to next control
If dgv.Rows(e.RowIndex).Cells(e.ColumnIndex).ReadOnly Then
SendKeys.Send("{TAB}")
End If

"Bill" wrote:

"Aspnot" wrote:
Have you found a solution to this? I am trying to do the exact same thing
and got the same error. Selecting the next cell is not an option, the next
cell needs to have the focus and be editable.


No I'm afraid I have found no solution.

Bill.

Feb 10 '06 #8

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

Similar topics

7
by: JimO | last post by:
I teach HS computers and one of my kids has a web site with a textbox of info that the user can scroll down and read. The problem is that users can also enter text into it. Is there a way, or a...
4
by: redryderridesagain | last post by:
My macro is writing to a table(T) and reading a query (Q) based on that table (VBA/Visual Basic 6.3). I cannot write T and read Q in the same execution of the macro, however, if I skip the writing...
3
by: dnl | last post by:
I have a parameter query that I would like to simplify so that I wouldn't need to use wildcards when entering in partial data. The following line is in the criteria field when designing the query:...
2
by: Paul Brady | last post by:
I have non-computer skilled users entering data into a form. There are certain ranges of values which, if they enter them, make no sense in the application, but I can't test them until they try to...
2
by: dave | last post by:
Hi. I am tring to read from random parts of an SDF file using a stream reader. I know each line in my file is 30 chars long so I know where in the file I want to go to read a specific record. The...
4
by: gzaxar | last post by:
Hi to all in forum. It is my first post here. I am quite new in MsAccess programming. Here is a problem which i am facing to. I want to keep records of employees CV's. More specifically i want...
5
by: Hooyoo | last post by:
Hi, here. I write following codes: string password = Console.ReadLine(); I want users enter their passwords, but readline will show content of password when entering, so is there any way to...
2
by: robertns5411 | last post by:
I have two questions: 1) Say I have a form bound to a table. Assume the user is entering data into a new record at the bottom of the form. Now, suppose the user clicks a button on the form...
1
by: bizt | last post by:
Hi, I have a webpage where Im creating AJAX type requests by loading dynamic pages containg JavaScript into hidden iFrames. The reason I am opting for this method over XmlHttpRequest object...
4
by: Neil | last post by:
Having trouble with inserting a record into a table. It's a list of names. But, for some reason, it won't take a particular name. When a user tries to enter a name into the table, the system hangs...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.