473,395 Members | 2,079 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,395 software developers and data experts.

Editing cells in a DataGridView

BRawn
28
Hi guys,

I'm busy writing an Orders application and one of the columns in the DGV is editable so the user can type in the order amount of the product. I'd like to know if there's a way to set focus to a particular cell so that if there's more than one item in the DGV and the user presses the Enter key, the next cell (Order amount) will be selected. The user must just be able to type in another amount without first having to click on the cell. Ive tried a couple of things already but nothing seems to work properly without the user first having to click on the cell to set focus on the cell and begin typing in the order amount.

There's no Cell.Focus() method and even though I've tried

Expand|Select|Wrap|Line Numbers
  1.  
  2. DataGridView1.Rows[DataGridView1.CurrentRow.Index].Cells["columnName"].Selected = true;
  3.  
  4.  
it still doesn't work.

This is what I have on the DGV's KeyUp event:

Expand|Select|Wrap|Line Numbers
  1.  
  2.         private void DataGridView1_KeyUp(object sender, KeyEventArgs e)
  3.         {
  4.                 if (e.KeyCode == Keys.Enter)
  5.                 {
  6. DataGridView1.Rows[DataGridView1.CurrentRow.Index].Cells["columnName"].Selected = true;
  7.                     int columnIndex = int.Parse(DataGridView1.Columns["columnName"].Index.ToString().Trim());
  8.                     int rowIndex = int.Parse(DataGridView1.Rows[DataGridView1.CurrentRow.Index].ToString().Trim());//.Cells["columnName"].Value.ToString().Trim()) - 1;
  9.                     DataGridView1.CurrentCell = DataGridView1[columnIndex, rowIndex];
  10.                     DataGridView1.BeginEdit(true);
  11.                 }
  12.         }
  13.  
  14.  
I've looked on the internet and there's really no other way that really works so I had to throw together my own solution but it doesn't seem to work either. Any light on this would be greatly appreciated :)
Dec 10 '10 #1
1 21794
BRawn
28
Nevermind guys...I got it :)

I apologize for the mistake I made here:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  int rowIndex = int.Parse(DataGridView1.Rows[DataGridView1.CurrentRow.Index].ToString().Trim());
  3.  
  4.  
It's actually supposed to be:

Expand|Select|Wrap|Line Numbers
  1.  
  2. int rowIndex = DataGridView1.CurrentRow.Index;
  3.  
  4.  
It works as it is...I just made a stupid mistake :$
Dec 10 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: bob | last post by:
I'm using the DataGridView control, with EditMode set to "edit programatically" and SelectionMode set to "FullRowSelect" (or something like that). My program allows the User to go into edit mode by...
3
by: Bob | last post by:
Hi, FrameWork 2.0 Quick and dirty job so I thought I would do it all on the UI as quick and easy as possible. I got the datagridview to display my Access databaseview by using the Datasources...
0
by: MKBender | last post by:
Hello everyone, What I'm currently trying to do is allow a user to add a row to my datagridview. I have AllowUserToAddRows set to true. And the empty now does appear at the bottom of my data. ...
0
by: ME | last post by:
I have an application that displays data in a DataGridView. The data is in a DataView that is sorted and at times filtered. One of the columns I have in the dataview is a boolean field called...
1
by: =?Utf-8?B?TWF6?= | last post by:
I have a datagridview (Winforms vb.net) whose datasource is a class I have constructed. I want to allow users to edit the cells in the grid and I can't. The MS documentation states that for this to...
1
by: Spitje | last post by:
Hello, Is it possible to save the data back to the csv file when editing the datagridview ? I don't want to loop thru the datatable and write each line. To read csv: Private Conn As...
0
by: Eric B. | last post by:
I have an Image column. How do I get back the filename of the image in a given cell? When I try to get the .Value of the cell all I get is "System.Image.Bitmap". I am also a bit troubled by...
4
by: BD | last post by:
I have an MDI application with a datagridview on a childform1 that will open childform2 with a double-click event on childform1. Childform2 works on a record and upon closing I want the...
0
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
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...
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
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,...
0
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...
0
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,...
0
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...
0
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...

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.