473,802 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you bypass cells in a "DataGridVi ew"

Does anyone know if it's possible to prevent a user from entering a
particular "DataGridVi ew" cell. I simply want to redirect them into the next
available cell but nothing I try works. Setting the "CurrentCel l" property
for instance causes no end of problems. If I call it in a "CellEnter"
handler I get the error "Operation is not valid because it results in a
reentrant call to the SetCurrentCellA ddressCore function" (which others on
the web have also reported). If I call it in a "CellMouseD own" handler it
works when right-clicking but not left-clicking. In other handlers it causes
a stack overflow. Does anyone know how to pull this off. Thanks.
Mar 9 '07 #1
4 8458
On Mar 9, 12:13 pm, "Michael Torville" <no_spam@_nospa m.comwrote:
Does anyone know if it's possible to prevent a user from entering a
particular "DataGridVi ew" cell. I simply want to redirect them into the next
available cell but nothing I try works. Setting the "CurrentCel l" property
for instance causes no end of problems. If I call it in a "CellEnter"
handler I get the error "Operation is not valid because it results in a
reentrant call to the SetCurrentCellA ddressCore function" (which others on
the web have also reported). If I call it in a "CellMouseD own" handler it
works when right-clicking but not left-clicking. In other handlers it causes
a stack overflow. Does anyone know how to pull this off. Thanks.
Michael:

I have a few thoughts. First, have you set the DataGridView's
MultiSelect, SelectionMode, or EditMode attributes or left them on
their default settings? If you could show us your code for when you
create your DataGridView and when you set it's attributes that would
help.

I agree that using the CellEnter event is a bad idea since that could
cause an infinite loop. I cannot replicate your problem with left
clicked when using the CellMouseDown event. I have tried using both
the CellMouseDown and the CellMouseClick events and they both register
for left-click and right-click. I'm hoping that once I know how you
have your attributes set I will be able to replicate your problem. If
possible please also supply your code for the CellMouseDown event.

~ Justin Creasy
www.immergetech.com
www.immergecomm.com

Mar 9 '07 #2
Here is some code that postpones setting the current cell using a
timer in CellEnter to prevent cell 2,2 becoming current. There is a
flash when you try clicking, but the arrow keys and tab keys seem to
work better.

private int skipRow = 2;
private int skipCol = 2;
private int oldRow = -2;
private int oldColumn = -2;

void dataGridView1_C ellEnter(object sender,
DataGridViewCel lEventArgs e)
{
if (e.RowIndex == skipRow && e.ColumnIndex == skipCol)
{
if (Control.MouseB uttons == MouseButtons.No ne)
{
if (oldRow == skipRow - 1 && oldColumn == skipCol)
{
oldRow = skipRow + 1;

}
else if (oldRow == skipRow && oldColumn == skipCol
- 1)
{
oldColumn = skipCol + 1;
}
else if (oldRow == skipRow + 1 && oldColumn ==
skipCol)
{
oldRow = skipRow - 1;

}
else if (oldRow == skipRow && oldColumn == skipCol
+ 1)
{
oldColumn = skipCol - 1;
}
}
Timer t = new Timer();
t.Interval = 5;
t.Tick += new EventHandler(t_ Tick);
t.Start();
}
}

void t_Tick(object sender, EventArgs e)
{
Timer t = sender as Timer;
t.Stop();
this.dataGridVi ew1.CurrentCell =
this.dataGridVi ew1[oldColumn, oldRow];
t.Tick -= new EventHandler(t_ Tick);
}

void dataGridView1_C ellLeave(object sender,
DataGridViewCel lEventArgs e)
{
oldRow = e.RowIndex;
oldColumn = e.ColumnIndex;
}
==============
Clay Burch
Syncfusion, Inc.

Mar 10 '07 #3
I have a few thoughts. First, have you set the DataGridView's
MultiSelect, SelectionMode, or EditMode attributes or left them on
their default settings? If you could show us your code for when you
create your DataGridView and when you set it's attributes that would
help.
Thanks for the feedback. I've have in fact set all of the above using the VS
forms designer so it all takes place in "InitializeComp onent()"

MultiSelect = false
SelectionMode = CellSelect
EditMode = EditOnKeystroke OrF2
I agree that using the CellEnter event is a bad idea since that could
cause an infinite loop.
I've taken precautions against this. The error I cited previously however
appears to be a bug not only because I've read about others who have the
same problem, but because the manager of the "DataGridVi ew" class at MSFT
(Mark Rideout) acknowledged it's a bug under other circumstances (on the
MSFT forums site).
I cannot replicate your problem with left
clicked when using the CellMouseDown event. I have tried using both
the CellMouseDown and the CellMouseClick events and they both register
for left-click and right-click. I'm hoping that once I know how you
have your attributes set I will be able to replicate your problem. If
possible please also supply your code for the CellMouseDown event.
Well, I just tried this by creating a new app out-of-the-box. I added a
"DataGridVi ew" as the only control on the form with two textbox columns. I
then created a "CellMouseD own" handler as follows:

private void m_Grid_CellMous eDown(object sender,
DataGridViewCel lMouseEventArgs e)
{
if (e.ColumnIndex == 0)
{
m_Grid.CurrentC ell = m_Grid[1, 0];
}
}

When the app starts, column 0 is automatically the current column. If I now
right-click column 0 then the handler is called (just once) and column 1
becomes current as expected. If I left-click column 0 however then the
handler is also called (just once) but column 0 remains current. I can
understand why this is probably occurring (left-clicking makes the cell
current *after* the handler exits) but it's incorrect behaviour IMO (since
the handler's code should override the left-mouse click). Any ideas? Thanks.
Mar 12 '07 #4
Thanks. I'll take a look at this but in all honesty, the timer makes me
nervous. I'm not sure why a timer is needed here but I'll reserve judgment
until I review it :) Thanks again.
Mar 12 '07 #5

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

Similar topics

0
2090
by: Martin Widmer | last post by:
Hello again! I have a datagridview control on my form and am using VS.Net 2005. One column is set up as combo box column, and when I try to set the datasource for that combobox column at design time in the properties section of VS, I get the error "object reference not set to instance of an object" and the only option is to click OK. I have not yet tried to set that datasource at runtime, but of course I could do that. But I don't...
8
4857
by: Pieter | last post by:
Hi, I'm having some weird problem using the BackGroundWorker in an Outlook (2003) Add-In, with VB.NET 2005: I'm using the BackGroundWorker to get the info of some mailitems, and after each item I want to raise the ProgressChanged-event to update the DataGridView. It works fine when only one Progresschanged is fired, but at the second, third, fopurth etc it raises everytile a 'Cross-thread operation not valid"-exception on lmy...
3
2053
by: Pieter Coucke | last post by:
Hi, When a user types a non numeric-value in a numeric column in a DataGridView, and he tries to leave the cell, he gets this "Input string was not in a correct format."-exception. Is there a (nice) way to get rid of this exception? And just put a "0" in the place? Or somehow trigger this single exception (does exceptions have a unique type-number?) and do some appropriate actions?
0
2234
by: romancoelho | last post by:
Hey everyone, I know this has to be simple, but can't figure out how to do it. How can I display the grid lines in all rows in the gird. The default behavior of the DataGridView seems to be that it only shows grid lines around rows that have data in it. If there are not enough rows to fill the height of the grid, then the grid lines don't show up around the "empty rows" I say "empty rows" because there actually a row there. So it seems...
0
4776
by: lgalumbres | last post by:
Hello, I have a DataGridView control with a DataGridViewComboBoxColumn that allows users to choose selections from a list. The DataGridView is bound to a DataTable object and the DataGridViewComboBoxColumn is bound to a DataTable as well and the link between the two tables is by a field called "ClassID" which is of integer data type. Both DataTables are populated from a server call. With the DataGridViewComboBoxColumn a user is...
3
12020
by: Sugandh Jain | last post by:
Hi, I am using property like this.. private DateTime? _propName; public DateTime? PropName { get { return _propName; }
3
1795
by: =?Utf-8?B?UmljaA==?= | last post by:
I need to build a sql string that looks like this: strSql = "Select * from tbl1 Where x In (123,456,789)" or strSql = "Select * from tbl1 Where x In (123,456,789,527,914)" The numbers represent RecordID's from rows I will select from a datagridview. I tried storing these values in an arrayList, and even a string array and tried this:
1
3764
by: Aegixx | last post by:
Ok, extremely wierd situation here: (I'll post the code below, after the explanation) I've got a Windows application (.NET 3.5) that has a single Form with a DataGridView embedded. The user presses a button to do a SQL query (fill a DataSet). Before firing the query, I disable the grid/buttons and turn on UseWaitCursor. After it completes, I re-enable the grid/ buttons, refresh the dataset, then turn off the UseWaitCursor. If I...
0
918
by: Rich P | last post by:
you could establish a formula where you count the number of characters being displayed when the column width is 50 and then how many chars are displayed with the width is 60, 70, ... Then if the text in a given cell exceeds the number of chars you counted for a given width - you can perform some action - widen the column programmatically, bring up a messagebox, ... Rich
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.