Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridView cell value change/update triggered from a graphing control via mouse click?
 

DataGridView cell value change/update triggered from a graphing control via mouse click?

Hi all,

Here is what I am trying to accomplish. I am using the ZedGraph control (coding using C++/Cli) and am trying to save the current mouse position on the graph using a combination of mouse button pressed and the 'Alt' key. I've accomplished this with the following code.
private: System::Boolean zGC_MouseDownEvent(ZedGraph::ZedGraphControl^  sender, System::Windows::Forms::MouseEventArgs^  e) 
	  {
		  if(sender->ModifierKeys == Keys::Alt)
		  {
			  // Save the mouse location
			PointF^ mousePt = gcnew PointF( e->X, e->Y );
			// Find the Chart rect that contains the current mouse location
			GraphPane^ pane = sender->MasterPane->FindChartRect( *mousePt );
			if(pane)
			{
				double x, y;
				pane->ReverseTransform(*mousePt, x, y);
				System::Windows::Forms::MessageBox::Show("Mouse Y value: " + y.ToString("f6"));
			}
		  }
		return false;
	  }
What I would like to do is add the x and y values that I've saved in the MouseDownEvent directly to a DataGridView programmatically (unbound). The display grid is in the Form directly below the graph and its purpose is simply to store and display x,y coordinates whenever that particular key/mouse combination is pressed. Every time it is pressed the cell in focus should receive the x,y coordinates and then the focus should shift to the next cell. Any suggestions on how to do this? I'm not sure if my description is clear enough as to what I'm trying to do so please feel free to ask/suggest information that I might be missing.

Cheers,
Alex
Just_Alex  Tuesday, August 04, 2009 10:18 PM
As it turns out this is actually far easier than I was making it out to be. I spent some more time playing around with it and stumbled on the solution:

Inside the brackets of the if(pane) {}, while the x and y values are still in scope simply add:

myDGView->CurrentCell->Value = y;

which would add the y value to the cell in focus. The rest is just formatting. :)

Alex

Trial and error wins again!
  • Marked As Answer byJust_Alex Tuesday, August 04, 2009 10:42 PM
  •  
Just_Alex  Tuesday, August 04, 2009 10:42 PM
As it turns out this is actually far easier than I was making it out to be. I spent some more time playing around with it and stumbled on the solution:

Inside the brackets of the if(pane) {}, while the x and y values are still in scope simply add:

myDGView->CurrentCell->Value = y;

which would add the y value to the cell in focus. The rest is just formatting. :)

Alex

Trial and error wins again!
  • Marked As Answer byJust_Alex Tuesday, August 04, 2009 10:42 PM
  •  
Just_Alex  Tuesday, August 04, 2009 10:42 PM

You can use google to search for other answers

Custom Search

More Threads

• datagrid tablestyles
• Databing Problem (Control.Visible==false)
• Using flags to indicate updates,insert,delete
• My database is always empty?? can someone point out the obvious??
• Column spanning cell editor
• Custom DataBinding - intercept before property access
• bindingNavigator1.BindingSource = (BindingSource)((DGV)sender).DataSource;
• proplem when adding collection as a property to the datagridviewcomboboxcolumn
• MustInherit
• Problem with startup form.