Create cross hair over C1FlexGrid

Posted by: office on 20 March 2018, 10:48 pm EST

    • Post Options:
    • Link

    Posted 20 March 2018, 10:48 pm EST

    Hi all

    Has anyone ever created a cross hair type overlay on to a c1flexgrid?

    I have a requirement to update a cross hair style pointer so that the user can see what the actual values are which are updated based on an event.

    The flex grid has a fixed number of rows and columns, and the values will be fixed for the session.

    For example, the flexgrid may have 20 row and 10 columns.

    The rows would typically have a range of 0 to 10,000, and the columns from 0 - 100.

    If the current value of the y axis was 5250, and the x axis was 57, the lines would appear off centre from the flexgrid cells.

    If, at the next update, the y axis value was 59, vertical component of the cross hair would move across to display this.

    If a visual example would help, please let me know.

  • Posted 21 March 2018, 9:00 pm EST - Updated 3 October 2022, 5:57 pm EST

    Hello,

    That is an interesting requirement in terms of Grid. We already have CrossHair feature in our Chart related controls, but not in Grid.

    However, this is easy to implement, since we just need cell changed and style the left edge for that column and top that row.

    Though, its beyond the scope to show complete implementation here, I have shared the main statements here:

    private void C1FlexGrid1_OwnerDrawCell(object sender, C1.Win.C1FlexGrid.OwnerDrawCellEventArgs e)
    {
       CellStyle s = c1FlexGrid1.GetCellStyle(e.Row, e.Col);
       if (s.Name == "HorizontalBorder")
       {
              Margins marginHz = new Margins(0,0,3,0);
              Rectangle rec;
              Graphics gr = e.Graphics;
              rec = e.Bounds;
              rec.Height = marginHz.Top;
               gr.FillRectangle(_bdrBrush, rec);
               prevRow = e.Row;
        }
    }
    //similarly for VerticalBorder and Intersection Border
    

    Here is the output generated with this approach.



    For complete implementation, please refer attached sample application.

    Regards,

    Ruchir Agarwal

    CrossHair_C1FlexGrid.zip

  • Posted 22 March 2018, 4:26 am EST - Updated 3 October 2022, 5:58 pm EST

    Thanks Ruchir

    That’s almost what I want, but not quite.

    The cross hair can move across the cell, it won’t only be on the border.

    I’m currently going to try to paint the line in the flexGrid_Paint event, and see if I can make it work that way. However, I think removing the line will be tricky.

    If you have any other suggestions, they would be appreciated.

  • Posted 22 March 2018, 10:04 pm EST - Updated 3 October 2022, 5:58 pm EST

    Hello,

    For showing the Crosshair in between the cell, we have tweaked the code a little. Following is the output observed now:



    Also, attached is modified sample application.

    Regards,

    Ruchir AgarwalCrossHair_C1FlexGrid1.zip

  • Posted 27 March 2018, 3:32 am EST

    Hi Ruchir

    Thank you very much for that example, it has helped me to create the functionality I need.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels