views:

2838

answers:

3

This error comes out whenever I clicked the datagrid.

Program does fill the datagrid every time data was selected in the combobox. For example: I choose data1 which has 4 records in datagrid. then I click row index no 1. No problem will shown but when I choose again another data in combobox, for example: Data 2 has only 1 record then I will clicked again the datagrid. This is the time that error will pop up.

Please see Code on how I fill the data grid:

Sub FillDtgPir(ByVal qry As String)
    Try
        If SQLConn1.State = ConnectionState.Closed Then SQLConn1.Open()
        Dim adap As New SqlDataAdapter(qry, SQLConn1)
        Me.DtsLineReq1.PRRMS_PIR.Clear()
        adap.Fill(Me.DtsLineReq1, "PRRMS_PIR")
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

Is there missing in the code?

+1  A: 

If the selected row index is larger than the largest index (number of rows minus one) in the new data, then decrease the row index as necessary before doing the fill? Or check the reason for the exception and decrease the row index instead of displaying the error message?

Windows programmer
A: 

When refilling the datagrid - make sure you reset the selected row (which is what I'd expect the Clear() to do).

An index outside the bounds of the array is usually caused by you trying to see a row that isn't there anymore. Do you have a pointer to the current row in the datagrid anywhere?

Is anything happening in the datagrid click event?

Brody
A: 

I have same issue. Always I get "Index out of............." Here is my code:

Dim MyText As TextObject 'Dim min As FieldObject

     For x = 0 To ChLBoxReportsSelect.CheckedItems.Count - 1

        rpt.DataDefinition.FormulaFields("Field1").Text = CStr(ChLBoxReportsSelect.CheckedItems(0).ToString())

        MyText = CType(rpt.ReportDefinition.ReportObjects("Column1"), TextObject) 'I am getting error message here, Column1 is strongly typed DataTable, this column will be used to populate crystal report column dynamically
        MyText.Text = ChLBoxReportsSelect.CheckedItems(x).ToString()

    Next x

Could some one please help me.

Kiran