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

Datagrid Cell Control in C#

I was trying to do when you press enter in a cell you can move to the next one, I am using this code:

Expand|Select|Wrap|Line Numbers
  1. protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg,System.Windows.Forms.Keys keyData)
  2.         {
  3.             if(msg.WParam.ToInt32() == (int) Keys.Enter)
  4.             {
  5.             SendKeys.Send("{Tab}");
  6.             return true;
  7.             }
  8.             return base.ProcessCmdKey(ref msg, keyData);
  9.         }
  10.  
It works very very nice =) but my current problem is, I dont want that to process to execute when the cell text lenght is = 0, I mean, if the cell is empty, the program doesnt allow you to change from the current cell. Thanks
Apr 3 '07 #1
2 1395
for example

Expand|Select|Wrap|Line Numbers
  1. private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
  2.         {
  3.             if (this.dataGridView1.CurrentCell.Value !=="")
  4.             {
  5.                  //Do not allow to lost focus on cell
  6.             }
  7.  
  8.         }
  9.  
Apr 3 '07 #2
The correct way to do what I wanted was using validating event
example

Expand|Select|Wrap|Line Numbers
  1. private void dataGridView1_CellValidating(object sender,DataGridViewCellValidatingEventArgs e)
  2.         {
  3.             if (Convert.ToString(e.FormattedValue) == "")
  4.             {
  5.                 e.Cancel = true;
  6.             }
  7.         }
I hope if anyone have my problem this helps
Apr 3 '07 #3

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

Similar topics

0
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some...
2
by: Tolga | last post by:
How do insert a user control i have created into a datagrid cell. Basically i am trying to create a column of my user controls. This is what i have tried so far. int i = 0; while (i <...
2
by: news | last post by:
Hello All, As a VB6/C/C++ (and some Java) developer, I've been toying with c# for the last couple of weeks. I'm currently trying to create a grid of 3x3 with each cell containing numbers from 1...
4
by: Suzanne | last post by:
Hi all, I'm having problems with datagrids and the currentcellchanged event. My problem is this: I have a datagrid on a form, if the user changes the text in a cell on the datagrid then tries to...
13
by: pmcguire | last post by:
I have a DataGrid control for which I have also created several new extended DataGridColumnStyles. They behave pretty nicely, but I can't figure out how to implement Selected Item formatting for...
0
by: Grant Smith | last post by:
I've been creating my own datagrid control which I'm inheiriting from the standard datagrid control and I have come across two very interesting behaviors with the datagrid control. 1. If you...
3
by: Ryan Liu | last post by:
Can someone give a sample to prevent a row from being deleted in a datatable? I tried e.Row.RejectChanges(); in dt_RowDeleting() but seems does not work. I need verify if there other data...
15
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an...
2
by: Sharon | last post by:
I want put into my DataGrid different control types in the same column. For example: Column 1, row 0 ==> TextBox Column 1, row 2 ==> CheckBox Column 1, row 2 ==> ComboBox etc... As I see, I...
2
by: jock1up | last post by:
I am working with editing within a DataGrid control cell and am confused about which events occur after the editing is completed. I see that 5 events can occur total, including the ones below and...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.