Page 1 of 1

How to allow a user to enter a value

Posted: Thu May 29, 2008 11:51 pm
by 8739068
I like the DragPoint tool on the chart, but I have a need where I want to give the user the option to right click or double click on a point of a series and a text box appears above the point and allows the user to enter a value in instead of dragging the point.

I can capture a double click on the chart but it is associated with the chart location and not a point. It would be most convenient if the point I could drag would have a MouseDoubleClick event I could subscribe to it.

I do have the source, maybe you could suggest some code I could add to the source that would implement this?

Thanks

Posted: Fri May 30, 2008 9:14 am
by narcis
Hi Mike,

You can easily achieve what you request using code below. You should replace the constant values I'm adding for the text boxes values.

Code: Select all

		public Form1()
		{
			InitializeComponent();
			InitializeChart();
		}
				
		private void InitializeChart()
		{
			Steema.TeeChart.Styles.Points points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
			points1.FillSampleValues();

			Steema.TeeChart.Tools.DragPoint dragPoint1 = new Steema.TeeChart.Tools.DragPoint(tChart1.Chart);
			dragPoint1.Series = points1;

			tChart1.DoubleClick += new EventHandler(tChart1_DoubleClick);
			tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
		}

		private int SeriesIndex = -1;
		private int ValueIndex = -1;		

		void tChart1_MouseDown(object sender, MouseEventArgs e)
		{
			for (int i = 0; i < tChart1.Series.Count; i++)
			{
				ValueIndex = tChart1[i].Clicked(e.X, e.Y);

				if (ValueIndex != -1)
				{
					SeriesIndex = i;
					break;
				}				
			}
		}

		void tChart1_DoubleClick(object sender, EventArgs e)
		{
			if (SeriesIndex != -1)
			{
				tChart1[SeriesIndex].XValues[ValueIndex] = 5;
				tChart1[SeriesIndex].YValues[ValueIndex] = 5;
				tChart1[SeriesIndex].Repaint();
			}			

			SeriesIndex = -1;
			ValueIndex = -1;
		}		
Hope this helps!