【问题标题】:Argument 1: cannot convert from 'Infragistics.WebUI.UltraWebGrid.UltraGridRow' to 'Infragistics.Web.UI.GridControls.ControlDataRecord'参数 1:无法从“Infragistics.WebUI.UltraWebGrid.UltraGridRow”转换为“Infragistics.Web.UI.GridControls.ControlDataRecord”
【发布时间】:2012-08-14 22:36:25
【问题描述】:

我正在将一堆代码从 vb.net 转换为 c#,但我不太了解 vb.net,所以遇到了很多问题。

谁能帮我看看这里出了什么问题?

protected void GenerateSalaryPunchesTable()
        {
            this.dgvPunchs.Rows.Clear();

            string[] DateRange = this.cboPayPeriods.SelectedItem.Text.ToString().Replace(" ", "").Split('-');

            while (Convert.ToDateTime(DateRange[0]) <= Convert.ToDateTime(DateRange[1]))
            {
                if (Convert.ToDateTime(DateRange[0]).DayOfWeek != DayOfWeek.Saturday & Convert.ToDateTime(DateRange[0]).DayOfWeek != DayOfWeek.Sunday)
                {
                    Infragistics.WebUI.UltraWebGrid.UltraGridRow nRow = new Infragistics.WebUI.UltraWebGrid.UltraGridRow();

                    nRow.Cells.Add();
                    // Date Cell
                    nRow.Cells.Add();
                    // Worked CB
                    nRow.Cells.Add();
                    // Vacation CB
                    nRow.Cells.Add();
                    // Sick CB
                    nRow.Cells.Add();
                    // Holiday CB
                    nRow.Cells.Add();
                    // Error

                    nRow.Key = Convert.ToDateTime(DateRange[0].ToString()).ToShortDateString();
                    nRow.Cells[0].Value = Convert.ToDateTime(DateRange[0].ToString()).ToShortDateString();
                    nRow.Cells[1].Value = 0;
                    nRow.Cells[2].Value = 0;
                    nRow.Cells[3].Value = 0;
                    nRow.Cells[4].Value = 0;
                    nRow.Cells[5].Value = "";

                    this.dgvPunchs.Rows.Add(nRow);
                }

                DateRange[0] = Convert.ToDateTime(DateRange[0]).AddDays(1);
            }

        }

这是它给我的错误:

错误 4 'Infragistics.Web.UI.GridControls.ControlDataRecordCollection.Add(Infragistics.Web.UI.GridControls.ControlDataRecord)' 的最佳重载方法匹配有一些无效参数
错误 5 参数 1:无法从“Infragistics.WebUI.UltraWebGrid.UltraGridRow”转换为“Infragistics.Web.UI.GridControls.ControlDataRecord”

这里是控件:

<ig:WebDataGrid ID="dgvPunchs" runat="server" Height="350px" Width="400px">
                        </ig:WebDataGrid>

它是从 VB.net 和旧版本的 Infragistics 转换而来的。到目前为止,我无法弄清楚。

编辑:

我试过了,还是不行……

Infragistics.Web.UI.GridControls.ControlDataRecord nRow =
  Infragistics.Web.UI.GridControls.ControlDataRecord();
//Infragistics.WebUI.UltraWebGrid.UltraGridRow nRow = new Infragistics.WebUI.UltraWebGrid.UltraGridRow();

【问题讨论】:

  • 异常中不明显吗?您正在尝试将 UltraGridRow 添加到 ControlDataRecord 对象的集合中...
  • 我认为错误发生在这个地方 this.dgvPunchs.Rows.Add(nRow); 你正在添加一行并且 dgvPunchs 接受 controldatarecord
  • 可能是新版本的基础设施改变了它的实现,所以现在它不是一个 UltraGridRow,而是一个 ControlDataRecord。我会看看他们文档中的任何重大更改。 C# 版本是否按原样工作?换句话说,它可能与您转换为 VB.NET 无关
  • @JeffMercado 我是 100% 的基础设施新手,以前从未使用过它们。你知道我怎么能解决这个问题。我试图添加代码(编辑了 OP),但没有奏效。我理解错误,只是不知道如何解决它。
  • @SimonMartin 是的,到目前为止我很茫然。叹息。

标签: c# asp.net infragistics webdatagrid


【解决方案1】:

发生异常是因为您将 UltraGridRow 添加到 WebDataGrid 或 WebHierarchicalDataGrid 的行集合,并且 UltraGridRow 与 UltraWebGrid 一起使用。

由于您更改了正在使用的网格,因此代码不会出现 1:1 映射,因此这会增加转换的复杂性。你最好先看看你想要完成什么,然后编写新的网格控件所需的代码。

对于数据行,WebDataGrid 通常使用 GridRecord 对象,您可以测试创建其中一个对象以向网格添加新行。

请注意,从您调用的方法看来,您正在为网格动态创建所有数据,如果是这种情况,那么您最好创建一个 DataTable 并将网格绑定到 DataTable,而不是直接使用网格,因为网格是为绑定数据而设计的。

【讨论】:

  • 这对我来说解释得更好。将尝试重写新的基础设施控件所需的方法。谢谢。
猜你喜欢
  • 2017-07-05
  • 1970-01-01
  • 2022-01-07
  • 1970-01-01
  • 2019-09-27
  • 2015-02-28
  • 2015-06-12
  • 2018-11-25
  • 2011-07-25
相关资源
最近更新 更多