Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

DataGridView cell events (KeyPressed)

$
0
0
Hi. I am using VS2010, C++/CLI Windows Forms Application
I want (Choose Cell in DVG, edit it, press Enter, get MessageBox with new value)

this->dataGridView1->EditingControlShowing += gcnew System::Windows::Forms::DataGridViewEditingControlShowingEventHandler(this, &Form1::dataGridView1_EditingControlShowing);
This event occurs when I am entering "Cell edit mode" 
Now I need event for KeyPress(I dont want messageBox appear everytime I type 1 symbol)

private: System::Void dataGridView1_EditingControlShowing(System::Object^ sender, System::Windows::Forms::DataGridViewEditingControlShowingEventArgs^ e)
		 {
			 TextBox^ txtbx = (TextBox^)e->Control;
			 if (txtbx != nullptr)
			 {
				 txtbx->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::txtbx_KeyPressed);
			 }
		 }
Now event for KeyPressed

private: System::Void txtbx_KeyPressed(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
		 {
			 if (e->KeyCode == System::Windows::Forms::Keys::Enter)
			 {
				 TextBox^ txtbx = (TextBox^)sender;
				 MessageBox::Show(txtbx->Text);
			 }
		 }
When I type single character into Cell value, I get through all events (f.e. I type intro cell 123, I come through txtbx_KeyPressed)
But when I press Enter, nothing happens (Event for Editing Cell just stops)
So I can call MessageBox everytime I type a single symbol into cell, but when I press Enter nothing happens

Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>