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

TextBox Example Into Datagridview

maheshwag
I have simple textbox example as below:

Expand|Select|Wrap|Line Numbers
  1.         private void Form1_Load(object sender, EventArgs e)
  2.         {
  3.             textBox1.Text = "Apple";
  4.         }
  5.  
  6.         private void textBox1_TextChanged(object sender, EventArgs e)
  7.         {
  8.             if (textBox1.Text.Length == 1) 
  9.             {
  10.                 if (textBox1.Text == "B" || textBox1.Text == "b") 
  11.                 {
  12.                     textBox1.Text = "Ball";
  13.                 }
  14.             }
  15.         }
  16.  
  17.  
By default textbox1 should return "Apple" on Form load but when I press "b" or "B" then it should return "Ball" on textbox1. I have a confusion on utilize it into datagridview. how can i do it in datagridview?.

Suppose I have One column on datagridview like below:

Expand|Select|Wrap|Line Numbers
  1.  
  2. private void Form1_Load(object sender, EventArgs e)
  3.         {
  4.             DataGridViewColumn Particulars = new DataGridViewTextBoxColumn();
  5.             dataGridView1.Columns.Insert(0, Particulars );
  6.  
  7.  
If I have above column In datagridview1 than How to do I with datagridview1 which I have did with textbox?.
Nov 23 '10 #1

✓ answered by maheshwag

This is a perfect solution of my problem:

Expand|Select|Wrap|Line Numbers
  1.   private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
  2.         {
  3.             int i = dataGridView1.CurrentCell.RowIndex;
  4.             if (this.dataGridView1.CurrentCell.ColumnIndex == 0)
  5.             {
  6.                 if (e.Control is TextBox)
  7.                 {
  8.                     TextBox dgvEditBox = e.Control as TextBox;
  9.                     dgvEditBox.TextChanged += new EventHandler(dgvEditBox_TextChanged);
  10.  
  11.                 }
  12.  
  13.             }
  14.  
  15.  
  16.         }
  17.  
  18.  
  19.         private void dgvEditBox_TextChanged(object sender, EventArgs e)
  20.         {
  21.             //Extract the textbox control
  22.             TextBox dgvEditBox = (TextBox)sender;
  23.  
  24.             //Insert the appropriate string
  25.             if (dgvEditBox.Text.Length == 1)
  26.             {
  27.                 if (dgvEditBox.Text == "B" || dgvEditBox.Text == "b")
  28.                 {
  29.                     dgvEditBox.Text = "Ball";
  30.                 }
  31.  
  32.  
  33.             }
  34.  
  35.             //Here I Revoke the access of EventHandler for prevent others columns to produce same result.Otherwise other columns would return the same result which column "[0]" return. 
  36.             dgvEditBox.TextChanged -= new EventHandler(dgvEditBox_TextChanged);
  37.  
  38.         }
  39.  
  40.  

3 4210
Leito
58
You could try to process your cell text when it is changed :
Expand|Select|Wrap|Line Numbers
  1. private void dataGridView_CellValidating(object sender, DataGridViewCellCancelEventArgs e) {
  2.     if (dataGridView.CurrentCell.Value.ToString() == "B") {
  3.          dataGridView.CurrentCell.Value = "Ball";
  4.      }
  5. }
N.B: Not sure that works, I wrote that without testing. But I think this is the good solution.
Nov 25 '10 #2
Leito, Sorry It's a not solution of my problem it's throw Error on Runtime Like "Null reference". Look at my Solution
Nov 26 '10 #3
This is a perfect solution of my problem:

Expand|Select|Wrap|Line Numbers
  1.   private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
  2.         {
  3.             int i = dataGridView1.CurrentCell.RowIndex;
  4.             if (this.dataGridView1.CurrentCell.ColumnIndex == 0)
  5.             {
  6.                 if (e.Control is TextBox)
  7.                 {
  8.                     TextBox dgvEditBox = e.Control as TextBox;
  9.                     dgvEditBox.TextChanged += new EventHandler(dgvEditBox_TextChanged);
  10.  
  11.                 }
  12.  
  13.             }
  14.  
  15.  
  16.         }
  17.  
  18.  
  19.         private void dgvEditBox_TextChanged(object sender, EventArgs e)
  20.         {
  21.             //Extract the textbox control
  22.             TextBox dgvEditBox = (TextBox)sender;
  23.  
  24.             //Insert the appropriate string
  25.             if (dgvEditBox.Text.Length == 1)
  26.             {
  27.                 if (dgvEditBox.Text == "B" || dgvEditBox.Text == "b")
  28.                 {
  29.                     dgvEditBox.Text = "Ball";
  30.                 }
  31.  
  32.  
  33.             }
  34.  
  35.             //Here I Revoke the access of EventHandler for prevent others columns to produce same result.Otherwise other columns would return the same result which column "[0]" return. 
  36.             dgvEditBox.TextChanged -= new EventHandler(dgvEditBox_TextChanged);
  37.  
  38.         }
  39.  
  40.  
Nov 26 '10 #4

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

Similar topics

1
by: Lumpierbritches | last post by:
Thank you in advance for any and all assistance, it is GREATLY appreciated. I was wondering if there is a way to tell Access 97 to compare the first line with other textboxes using the...
5
by: Te-Deum | last post by:
Hi, I have an application with a lot of Textbox. Do you know if I can set any Textbox Text only with the string name of the Textbox. Example : For the Textbox REXENP_CATEGW could I set the...
1
by: protista | last post by:
I need a simple dataset to textbox example that will show me how to "bind" (not that i know what that means) a textbox to data in my sql server. So.. basically i open the form with the ID of the...
0
by: sg_pl | last post by:
Hi I have a dataGridView, textBox, button RESET and label. When I change text in TextBox the dataGridView is filtering and I see only this date where text in field "name" is text in TextBox and...
5
by: Reny | last post by:
can any one tell how can i restrict my user to type just numeric character in the textbox.I am using VS.NET 2003 (VB.NET)
3
by: reidarT | last post by:
I have a datagrid with columns. One of the columns are a textbox. I want the text in this column shown in a textbox outside the datagrid. How can I do that when clicking the actual row in the...
1
by: Jeff | last post by:
Hey ..NET 2.0 I've created a User Control which contain a DataGridView. This User Control is displayed on a TabPage. This TabPage is added to the TabControl during runtime. The problem is...
12
by: cj | last post by:
When viewing a datatable in a datagridview one of the columns in it is a "note" field which can be quite long. I would like to have the note field of the currently selected row of the datagrid...
9
by: Miro | last post by:
My current headache is proper is with the datagridview I am starting to realize that a DataGridView within vs2008 is not as 'robust' as a 'textboxfield' by default for example. Example: A...
6
by: naseemsadak | last post by:
Hi, I'm developing a program in c# 2005 and would like to know if it is possible to refresh a tab page's controls(e.g textboxes, combobox, datagridview) when a different tab is selected so when i...
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: 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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.