473,566 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting CurrentCell in DGV in CellEndEdit event ignores RowIndex

I have a 2 column DGV. When a user enters a value in cell 0,0 I want to set
cell 0,1 as current, when they enter a value in cell 0,1 I want to set cell
1,0 current, etc, etc

basically zig-zagging down the rows from left to right.
I'm calling this method below in my CellEndEdit event:
private void AdvanceCellFocu s(DataGridViewC ellEventArgs e)
{
if (e.ColumnIndex == 0)
{
dataGridView_Se rialNumberLinks .CurrentCell =
dataGridView_Se rialNumberLinks[e.ColumnIndex + 1, e.RowIndex];
}
else
{
if (e.RowIndex < dataGridView_Se rialNumberLinks .Rows.Count)
{
dataGridView_Se rialNumberLinks .CurrentCell =
dataGridView_Se rialNumberLinks[e.ColumnIndex - 1, e.RowIndex
+ 1];
}
}
}

The result is this:
- Data entered into cell 0,0
- AdvanceCellFocu s() called and sets cell 0,1 as current
- when control returns to the UI, cell 1,1 is current.

So the problem appears to be that the default behavior of advancing a row
upon completing an edit operation is still happening. I'm not finding a way
to deal with it.

Anyone have any ideas? Suggestions?

Thanks for reading,
Steve
May 4 '07 #1
2 4568
I found this while googling:
http://forums.microsoft.com/MSDN/Sho...27470&SiteID=1

Basically suggest suppressing the enter key event, but that will also
prevent EditMode from committing and saving the data.

I think my new, refined question is: How to prevent DGV from advancing to
next row when 'entering' out of edit mode?
"sklett" <s@s.comwrote in message
news:eU******** ******@TK2MSFTN GP04.phx.gbl...
>I have a 2 column DGV. When a user enters a value in cell 0,0 I want to
set cell 0,1 as current, when they enter a value in cell 0,1 I want to set
cell 1,0 current, etc, etc

basically zig-zagging down the rows from left to right.
I'm calling this method below in my CellEndEdit event:
private void AdvanceCellFocu s(DataGridViewC ellEventArgs e)
{
if (e.ColumnIndex == 0)
{
dataGridView_Se rialNumberLinks .CurrentCell =
dataGridView_Se rialNumberLinks[e.ColumnIndex + 1, e.RowIndex];
}
else
{
if (e.RowIndex < dataGridView_Se rialNumberLinks .Rows.Count)
{
dataGridView_Se rialNumberLinks .CurrentCell =
dataGridView_Se rialNumberLinks[e.ColumnIndex - 1,
e.RowIndex + 1];
}
}
}

The result is this:
- Data entered into cell 0,0
- AdvanceCellFocu s() called and sets cell 0,1 as current
- when control returns to the UI, cell 1,1 is current.

So the problem appears to be that the default behavior of advancing a row
upon completing an edit operation is still happening. I'm not finding a
way to deal with it.

Anyone have any ideas? Suggestions?

Thanks for reading,
Steve

May 4 '07 #2
I found the solution. I needed to subclass the DGV to get to the key events
when in edit mode.
"sklett" <s@s.comwrote in message
news:uK******** ******@TK2MSFTN GP05.phx.gbl...
>I found this while googling:
http://forums.microsoft.com/MSDN/Sho...27470&SiteID=1

Basically suggest suppressing the enter key event, but that will also
prevent EditMode from committing and saving the data.

I think my new, refined question is: How to prevent DGV from advancing to
next row when 'entering' out of edit mode?
"sklett" <s@s.comwrote in message
news:eU******** ******@TK2MSFTN GP04.phx.gbl...
>>I have a 2 column DGV. When a user enters a value in cell 0,0 I want to
set cell 0,1 as current, when they enter a value in cell 0,1 I want to set
cell 1,0 current, etc, etc

basically zig-zagging down the rows from left to right.
I'm calling this method below in my CellEndEdit event:
private void AdvanceCellFocu s(DataGridViewC ellEventArgs e)
{
if (e.ColumnIndex == 0)
{
dataGridView_Se rialNumberLinks .CurrentCell =
dataGridView_Se rialNumberLinks[e.ColumnIndex + 1, e.RowIndex];
}
else
{
if (e.RowIndex < dataGridView_Se rialNumberLinks .Rows.Count)
{
dataGridView_Se rialNumberLinks .CurrentCell =
dataGridView_Se rialNumberLinks[e.ColumnIndex - 1,
e.RowIndex + 1];
}
}
}

The result is this:
- Data entered into cell 0,0
- AdvanceCellFocu s() called and sets cell 0,1 as current
- when control returns to the UI, cell 1,1 is current.

So the problem appears to be that the default behavior of advancing a row
upon completing an edit operation is still happening. I'm not finding a
way to deal with it.

Anyone have any ideas? Suggestions?

Thanks for reading,
Steve


May 4 '07 #3

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

Similar topics

2
16984
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of the columns of the data grid contains a DropDownlist. I managed to create this datagrid control as follows.
1
1603
by: melanieab | last post by:
Hi, I have a datagrid & a datatable, and when I use the mousemove event, I run into trouble. private void dgMouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { System.Windows.Forms.DataGrid.HitTestInfo hitInfo = dg.HitTest(new Point(e.X, e.Y)); .... // find out which cell is entered dg.CurrentCell = new...
5
8715
by: Bob | last post by:
In a datagridview (vs2005, VB.net) I have two columns that are checkboxes. I need to check that only one of the two can be checked. Its not permissible to have the two selected to true, but they can both be false. I wrote code in the cellvalidating event as follows. Private Sub Datagrid1_CellValidating(ByVal sender As Object, ByVal e As...
3
6419
by: Elmo Watson | last post by:
I previously had a project working, in which the Gridview was populated by a DataSet - then, with a DropDownlist in one of the columns, using the OnrowDataBound event, to populate the DDL with the correct item in the returned data, I had : myDDL.SelectedValue = IIf(IsDBNull(MyDataSet.Rows(e.Row.RowIndex).Item("Fieldname")), vbNullString,...
5
32593
by: Lennart Nielsen | last post by:
I can find the X and Y (column/row) coordinates, but not the actual location (Left,Top) positions. Any ideas? Lennart
4
31994
by: Paul | last post by:
Hello All, I have been trying to figure out how to set the BackColor of individual cells in a DataGridView. I found the following solution in a VB usenet group DataGridView1.Item(ColumnIndex, RowIndex).Style.BackColor = Color DataGridView1.Item(ColumnIndex, RowIndex).Style.ForeColor = Color or
1
12654
by: QuickBooksDev | last post by:
VB.NET 2005 DataGridView Checkbox - Check Event need to know check status I would like to use the DataGridView Checkbox like a normal checkbox. When someone clicks on it I would expect that I could get a checked or changed event and be able to test if the box was checked or unchecked. For a normal checkbox. When it is checked you can test...
0
2698
by: systeko | last post by:
Hello, I have one little problem which make me crazy. I've made application (for Windows) in Visual C#. On one panel I've got datagridview control which is not bind to database, I populate it manualy. It has 4 columns and only one can be edited and user can put some numbers in it (It is float type). I want to validate ie. to check if that...
3
5718
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows few celltemplate property getters and combobox/datecombo constructor calls without database access which does not take a lot of time. Debug...
0
7584
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...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8108
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7951
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...
0
6260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5213
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...
0
3643
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
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

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.