0

大量のコードを 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();
4

1 に答える 1

1

UltraGridRow を WebDataGrid または WebHierarchicalDataGrid の行コレクションに追加し、UltraGridRow が UltraWebGrid で使用されたため、例外が発生しています。

使用されているグリッドを変更したため、コードの 1:1 マッピングがなくなり、変換が複雑になります。達成したいことを確認してから、新しいグリッド コントロールに必要なコードを記述したほうがよいでしょう。

通常、データ行の場合、WebDataGrid は GridRecord オブジェクトを使用し、これらの 1 つを作成して新しい行をグリッドに追加することをテストできます。

呼び出しているメソッドから、グリッドのすべてのデータを動的に作成しているように見えることに注意してください。その場合は、グリッドを使用するよりも、DataTable を作成してグリッドを DataTable にバインドする方がよいでしょう。グリッドはデータにバインドされるように設計されているため、直接。

于 2012-08-15T01:42:55.043 に答える