从图表到datagridview [英] From chart to datagridview

查看:106
本文介绍了从图表到datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





是否可以在Datagridview中显示图表中的数据?我的方案是,如果用户右键单击图表,他们将获得一个选项,以数据网格视图的形式查看与图表关联的数据。



我尝试了什么:



目前我可以正确,它会显示一个空的数据视图。

Hi ,

Is it possible to display the data from a chart in a Datagridview? My scenario is if a user right clicks on a chart they will be given an options to view the data associated with the chart in the form of a datagridview.

What I have tried:

At the moment I can right and it brings up an empty datagriview.

推荐答案

在此了解如何解决您的请求。请记住,这可能不是最有效和最优雅的解决方案。现在,您的工作就是将它与上下文菜单结合在一起:)

Here an idea how you can solve your request. Keep in mind this would be probably not the most efficient and elegant solution. Now it is your Job to bring this together with your context menu :)
private void chartTest_MouseClick(object sender, MouseEventArgs e)
{
    HitTestResult ht = chartTest.HitTest(e.X, e.Y);
    if (ht.Series != null)
    {
        dataGridViewChart.Columns.Clear();
        dataGridViewChart.Columns.Add("ColX", "X");
        dataGridViewChart.Columns.Add("ColY", "Y");
        this.dataGridViewChart.Rows.Clear();

        foreach(var point in ht.Series.Points)
        {
            this.dataGridViewChart.Rows.Add(point.XValue, point.YValues[0]);
        }
    }
}

我希望它有所帮助。





http://www.dotnetperls.com/datatable [ ^ ] - >

I hope it helps.


http://www.dotnetperls.com/datatable[^]-->

警告:



DataGridView在手动添加行时存在性能问题。使用DataTable,List和DataSource有帮助。


DataGridView has performance problems with manually adding rows. Using DataTable, List and DataSource helps.


这篇关于从图表到datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆