ColorGrid-code continuous selection of cells in C# .Net v3

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
vivek
Newbie
Newbie
Posts: 40
Joined: Thu Jul 19, 2007 12:00 am

ColorGrid-code continuous selection of cells in C# .Net v3

Post by vivek » Wed Feb 04, 2009 9:35 am

Dear Support,

I have posted the below underlined question and received the response from you yesterday, Since I am using the TeeChart for .NET v3 version please send the mention code in the reply in c#. As you mentioned in your reply placing different icons for different cells is not supported please send the code to implement continuous selection of cells in c#.

Appreciate faster response as this feature is critical for our tool.

I want to select few cells in the color grid by mouse drag option is that possible. Continuous selection is supported in color grid.

Is that possible to add different images in different cells of color grid.


Thanks,
Muthu,
Jubilant Biosys.

Hi Muthu,

Quote:
I want to select few cells in the color grid by mouse drag option is that possible. Continuous selection is supported in color grid.


Yes, you can do something as what I suggested here.

Quote:
Is that possible to add different images in different cells of color grid.


You can use an image for the entire series, something as in the All Features\Welcome !\Chart styles\Statistical\Color Grid\ColorGrid Bitmap example in the features demo. However, it's not possible to use an image for each cell. If you let us know the TeeChart version you are using I'll add your request to the wish-list to be considered for inclusion in future releases.

Also we'd appreciate if you posted your technical inquiries at specific forum for the TeeChart version you are using. This way it would be easier for us to provide more accurate replies.

Thanks in advance.
_________________
Best Regards
Narcís Calvet

Steema Support Central

Yeray
Site Admin
Site Admin
Posts: 9587
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Wed Feb 04, 2009 12:30 pm

Hi Muthu,

Here there is the c# version of the code that Narcis pointed to you yesterday:

Code: Select all

public partial class Form1 : Form
    {
        int X0, X1, Y0, Y1, XIndex, YIndex;
        Boolean DrawRect; 
        
        public Form1()
        {
            InitializeComponent();
        }

        private Steema.TeeChart.Styles.ColorGrid colorGrid1;

        private void Form1_Load(object sender, EventArgs e)
        {
            colorGrid1 = new Steema.TeeChart.Styles.ColorGrid(tChart1.Chart);
            colorGrid1.FillSampleValues(10);
            tChart1.Zoom.Allow = false;
            tChart1.Aspect.View3D = false;
        }

        private void tChart1_MouseDown(object sender, MouseEventArgs e)
        {
            listBox1.Items.Clear();

            X0 = e.X;
            Y0 = e.Y;

            XIndex = colorGrid1.Clicked(new Point(e.X,e.Y));
            DrawRect = true;
        }

        private void tChart1_MouseMove(object sender, MouseEventArgs e)
        {
            if (DrawRect)
            {
                X1 = e.X;
                Y1 = e.Y;

                tChart1.Refresh();
            }
        }

        private void tChart1_MouseUp(object sender, MouseEventArgs e)
        {
            DrawRect = false;

            YIndex = colorGrid1.Clicked(X1,Y1);
            GetRectIndexes();

            tChart1.Refresh();
        }

        private void tChart1_AfterDraw(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            g.Pen.Color = Color.White;
            g.Pen.Width = 2;
            g.Brush.Visible = false;

            g.Rectangle(X0, Y0, X1, Y1);
        }

        private void GetRectIndexes()
        {
            int Col0, Row0, Col1, Row1;
            
            Col0 = GetColumn(XIndex);
            Row0 = GetRow(XIndex);
            Col1 = GetColumn(YIndex);
            Row1 = GetRow(YIndex);

            for (int x = Math.Min(Col0, Col1); x < Math.Max(Col0, Col1); x++)
                for (int z = Math.Min(Row0, Row1); z < Math.Max(Row0, Row1); z++)
                    listBox1.Items.Add(colorGrid1.YValues[(x * colorGrid1.NumXValues) + z]);
        }

        private int GetColumn(int ValueIndex)
        {
            return ValueIndex / (colorGrid1.NumXValues - 1);
        }

        private int GetRow(int ValueIndex)
        {
            return ValueIndex % (colorGrid1.NumZValues - 1);
        }
    }
I hope this helps.

EDIT: Code revised correcting errors found in later posts in this thread.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

vivek
Newbie
Newbie
Posts: 40
Joined: Thu Jul 19, 2007 12:00 am

Need multi point selection option in Points series

Post by vivek » Wed Apr 15, 2009 12:19 pm

Dear Yeray,

Multi-cell selection in Colorgrid is working fine.
Now i need to implement the same future in Points series also.
When i tried to convert the same code what i got for Colorgrid, i am facing some problem.
The following code always return -1 .
tChart1.Series[0].Clicked(new Point(e.X, e.Y));// PointsForSP[0].Clicked(X1, Y1);
It will help me, if you give any sample code/ application for multi point selection future in Points series.

With regards,
Muthu.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Apr 15, 2009 12:21 pm

Hi Muthu,

You could do the same as the examples discussed on this thread:

http://www.teechart.net/support/viewtopic.php?t=5385
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

vivek
Newbie
Newbie
Posts: 40
Joined: Thu Jul 19, 2007 12:00 am

Need multi point selection option in Points series

Post by vivek » Wed Apr 15, 2009 1:52 pm

Dear Nacis,

It is working fine.
Thank you.

icecream
Newbie
Newbie
Posts: 20
Joined: Thu Aug 07, 2008 12:00 am

Re:

Post by icecream » Tue Mar 22, 2016 11:52 am

Yeray wrote:

Code: Select all

private int GetColumn(int ValueIndex)
{
    return ValueIndex / colorGrid1.NumXValues;
}

private int GetRow(int ValueIndex)
{
    return ValueIndex % colorGrid1.NumZValues;
}
Hi Yeray,
Could you please explain how does GetRow method work? Why there are no NumYValues?
I have tried to get Col and Row in the same way and get following values:
Image

I would expect 0.0, 1.1, 2.2, 3.3 etc. as a diagonal cells. Could you suggest how can I do this?
Thanks.

Yeray
Site Admin
Site Admin
Posts: 9587
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Re:

Post by Yeray » Thu Mar 24, 2016 8:23 am

Hello,

First of all, after revising the code above I've done a small change at GetRectIndexes method to make it a bit more elegant: change this:;

Code: Select all

          listBox1.Items.Add(colorGrid1.YValues[(x * 10) + z]);
for this:

Code: Select all

          listBox1.Items.Add(colorGrid1.YValues[(x * colorGrid1.NumXValues) + z]);
icecream wrote:Could you please explain how does GetRow method work? Why there are no NumYValues?
GetRow returns the Index of the Row for the given ValueIndex.
NumXValues is the number of values/cells at each row.
NumZValues is the number of values/cells at each column.
NumYValues has little sense because YValues is used to represent the color of the values, not to represent rows/columns. If you want to know the total number of cells you can use the series' Count property.
icecream wrote:I have tried to get Col and Row in the same way and get following values:
Image

I would expect 0.0, 1.1, 2.2, 3.3 etc. as a diagonal cells. Could you suggest how can I do this?
How are you drawing that table?
I've tried this code:

Code: Select all

      for (int i = 0; i < colorGrid1.Count; i++)
          listBox1.Items.Add("c" + GetColumn(i) + " r" + GetRow(i));
gives me this:
c0 r0 ... c0 r9
c1 r0 ... c1 r9
...
c9 r0 ... c9 r9

Of course this is the result when populating the ColorGrid with FillSampleValues(10), that internally adds 10x10 values.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

icecream
Newbie
Newbie
Posts: 20
Joined: Thu Aug 07, 2008 12:00 am

Re: Re:

Post by icecream » Thu Mar 24, 2016 8:53 am

Yeray wrote: How are you drawing that table?
This is a code that creates color grid:

Code: Select all

for (int r = 1; r <= rCount; r++)
	for (int c = 1; c <= cCount; c++)
	{
		colorGrid1.Add(c, 0, r);
	}
This is how I get the values:

Code: Select all

private Point GetCellIndexes()
{
    return new Point(GetColumn(m_index), GetRow(m_index));
}

private int GetColumn(int ValueIndex)
{
    return ValueIndex / m_heatMapSeries.NumXValues;
}

private int GetRow(int ValueIndex)
{
    return ValueIndex % m_heatMapSeries.NumZValues;
}

private void m_chart_MouseClick(object sender, MouseEventArgs e)
{
    m_index = colorGrid1.Clicked(new Point(e.X, e.Y));
    Point p = GetCellIndexes();
}
There is no code for filling the table, I have added value by value clicking on each cell.

Yeray
Site Admin
Site Admin
Posts: 9587
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: ColorGrid-code continuous selection of cells in C# .Net v3

Post by Yeray » Thu Mar 24, 2016 9:20 am

Hello,
icecream wrote:
Yeray wrote: How are you drawing that table?

Code: Select all

for (int r = 1; r <= rCount; r++)
	for (int c = 1; c <= cCount; c++)
	{
		colorGrid1.Add(c, 0, r);
	}
This helped me to find a mistake in GetColumn&GetRow functions.
Using the following test code:

Code: Select all

      colorGrid1 = new ColorGrid(tChart1.Chart);
      int rCount = 9;
      int cCount = 8;

      for (int r = 1; r <= rCount; r++)
        for (int c = 1; c <= cCount; c++)
        {
          colorGrid1.Add(c, 0, r);
        }

      tChart1.Zoom.Direction = ZoomDirections.None;
      tChart1.Aspect.View3D = false;

      for (int i = 0; i < colorGrid1.Count; i++)
        listBox1.Items.Add("c" + GetColumn(i) + " r" + GetRow(i));
I get this:
c0 r0 ... c0 r9
c1 r0 ... c1 r9
...
c6 r0 ... c6 r9
c7 r0 c7 r1

That is obviously wrong. But changing the GetColumn&GetRow functions for the following:

Code: Select all

    private int GetColumn(int ValueIndex)
    {
      return ValueIndex / (colorGrid1.NumXValues - 1);
    }

    private int GetRow(int ValueIndex)
    {
      return ValueIndex % (colorGrid1.NumZValues - 1);
    }
the same example now gives this:
c0 r0 ... c0 r8
c1 r0 ... c1 r8
...
c7 r0 ... c7 r8

that is now correct.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply