【问题标题】:Add data manually to gridcontrol devexpress C#手动将数据添加到 gridcontrol devexpress C#
【发布时间】:2017-06-08 19:30:13
【问题描述】:

我在以编程方式向 devexpress 网格中添加数据时遇到了麻烦。我使用 HTML Agility Pack 解析来自站点的数据,并希望将解析后的数据添加到网格中。我使用向导在 gridcontrol 中创建了 13 列。

    private void buttonGetData_Click(object sender, EventArgs e)
    {
        string url = @"____";
        HtmlWeb web = new HtmlWeb();
        HtmlDocument document = web.Load(url);
        var node = document.DocumentNode.SelectNodes("//tr[not(@class)]/td[@style='width:1%;' or @class='coef' or (@class='left' and .//a)]");

        /*foreach (var innerText in node.Select(row => row.InnerText))
        {
            gridView1.AddNewRow();
            gridView1.SetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns["colunmDate"] , innerText);
            gridView1.UpdateCurrentRow();
        }*/
    }

我将大约 2000 个元素放入节点。在这段代码中,我从 Node.js 获取 InnerText。注释代码不起作用(它只是为了测试)。请帮我向 DevExpress Grid 添加数据。谢谢!

【问题讨论】:

    标签: c# devexpress


    【解决方案1】:

    假设 document 变量是格式良好的 Xml,您可以将其加载到 DataSet 实例中

    XmlTextReader MyReader = new XmlTextReader(new StringReader(Buffer));
    MyDataSet.ReadXml(MyReader, XmlReadMode.Auto);
    

    然后您可以直接将适当的表格附加为GridView1.DataSource,或者在附加之前对其进行转换。

    【讨论】:

    • 我尝试使用 BindingList 但也没有效果 (( ` public Coeff(string date, string time, string teams) { this.date = date; this.time = time; this.teams = teams ; }`
    • ` BindingList coeffs = new BindingList(); foreach (var innerText in node.Select(row => row.InnerText)) { coeffs.Add(new Coeff(innerText, innerText, innerText)); } gridControl1.DataSource = coeffs; gridControl1.RefreshDataSource(); }`
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-30
    相关资源
    最近更新 更多