0

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();
James Wilson
  • 5,074
  • 16
  • 63
  • 122
  • 1
    Is it not obvious in the exception? You are trying to add a `UltraGridRow` to a collection of `ControlDataRecord` objects... – Jeff Mercado Aug 14 '12 at 22:41
  • i think the error occurs at this place `this.dgvPunchs.Rows.Add(nRow);` you are adding a row and the dgvPunchs accepts controldatarecord – Waqar Janjua Aug 14 '12 at 22:42
  • It could be that the newer version of infragistics has changed its implementation so now instead of it being an UltraGridRow it is a ControlDataRecord. I would take a look at any breaking changes in their documentation. Does the C# version work as-is? In other words it might have nothing to do with your conversion to VB.NET – Simon Martin Aug 14 '12 at 22:42
  • @JeffMercado I am 100% new to infragistics, never used them before. Do you know how I can fix this. I tried to add the code (edited the OP) and that did not work. I understand the error, just not how to fix it. – James Wilson Aug 14 '12 at 22:48
  • @SimonMartin yeah, I am at a loss so far. Sigh. – James Wilson Aug 14 '12 at 22:49
  • @WaqarJanjua any idea where i can look or how to fix this? I am at a complete loss. Been looking this up for about 30 minutes. – James Wilson Aug 14 '12 at 23:02
  • You may want to look at the NetAdvantage for ASP.NET help: http://help.infragistics.com/NetAdvantage/ASPNET/2012.1/CLR4.0/ – alhalama Aug 15 '12 at 01:46

1 Answers1

1

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.

alhalama
  • 3,218
  • 1
  • 15
  • 21
  • That explained it much better for me. Will try and rewrite the method for how the new infragistics controls wants it. Thank you. – James Wilson Aug 15 '12 at 14:39