I am converting a bunch of code from vb.net to c# and I don't know vb.net very well so I am running into a lot of issues.

Can someone help me see what is wrong here?

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);
            }

        }

Here is the error it is giving me:

Error 4 The best overloaded method match for 'Infragistics.Web.UI.GridControls.ControlDataRecordCollection.Add(Infragistics.Web.UI.GridControls.ControlDataRecord)' has some invalid arguments
Error 5 Argument 1: cannot convert from 'Infragistics.WebUI.UltraWebGrid.UltraGridRow' to 'Infragistics.Web.UI.GridControls.ControlDataRecord'

And here is the control:

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

It was converted from VB.net and an older version of Infragistics. I cannot figure this out so far.

EDIT:

I tried this and it didn't work either...

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

There are 1 best solutions below

1
On BEST ANSWER

The exception is happening because your adding an UltraGridRow to a WebDataGrid or a WebHierarchicalDataGrid's rows collection and the UltraGridRow was used with the UltraWebGrid.

Since you have changed the grid that is being used there will not be a 1:1 mapping for the code so this will add complexity to the conversion. You will be better off looking at what you want to accomplish and then writing the code needed for the newer grid control.

Typically for data rows the WebDataGrid uses GridRecord objects and you could test creating one of these to add a new row to the grid.

Note that from the method that you are calling it appears that you are dynamically creating all of the data for the grid and if that it the case then you would be better off creating a DataTable and binding the grid to the DataTable rather than using the grid directly since the grid is designed to be bound to data.