This is a migrated thread and some comments may be shown as answers.

Binding two grids

2 Answers 56 Views
GridView
This is a migrated thread and some comments may be shown as answers.
KawaUser
Top achievements
Rank 2
KawaUser asked on 14 Dec 2011, 04:17 PM
I have 2 grids that I bind to when selecting a vendor from the drop down and click the search button(griderror.jpg shows before I click search). Before they get their data I add a command column to each grid, works with no problems. When I click the search button they both get their data with no problems and everything looks good(GridError2.jpg shows that the data properly populated). When I click the button in the command column of the first grid it does exactly what it is suppose to. If I click the command column in the 2nd grid it errors out with the original - Object reference is not set to an instance of an object. If I do not load the first grid, but just the 2nd grid it does not error out.

Private Sub rgvDocumentsPO_CommandCellClick(sender As Object, e As System.EventArgs) Handles rgvDocumentsPO.CommandCellClick
 
    Dim VendorID As Integer = ddlDocumentsVendor.SelectedValue
 
    Dim documentid As Integer = rgvDocumentsPO.CurrentRow.Cells("Document ID").Value
 
    If DataLayer.UnconfirmDocument(documentid) = True Then
 
        LoadDocuments(VendorID)
 
    Else
 
        RadMessageBox.Show("You can not unconfirm this document.")
 
    End If
 
End Sub
 
Private Sub rgvDocumentsDrawings_CommandCellClick(sender As Object, e As System.EventArgs) Handles rgvDocumentsDrawings.CommandCellClick
 
    Dim VendorID As Integer = ddlDocumentsVendor.SelectedValue
 
    'It errors out on this next line, but not the same line in the above Sub
    Dim documentid As Integer = rgvDocumentsDrawings.CurrentRow.Cells("Document ID").Value
 
    If DataLayer.UnconfirmDocument(documentid) = True Then
 
        LoadDocuments(VendorID)
 
    Else
 
        RadMessageBox.Show("You can not unconfirm this document.")
 
    End If
 
End Sub

This is the function that loads the grids

Public Sub LoadDocuments(ByVal VendorID As Integer)
 
    Try
 
        Dim CommandColumn As New GridViewCommandColumn
        CommandColumn.Name = "Unconfirm"
        CommandColumn.HeaderText = ""
        CommandColumn.DefaultText = "Unconfirm"
        CommandColumn.UseDefaultText = True
        CommandColumn.TextAlignment = ContentAlignment.MiddleCenter
 
        If rgvDocumentsDrawings.RowCount = 0 Then
 
            rgvDocumentsDrawings.Columns.Add(CommandColumn)
 
        End If
 
        If rgvDocumentsPO.RowCount = 0 Then
 
            rgvDocumentsPO.Columns.Add(CommandColumn)
 
        End If
 
    Catch ex As Exception
 
    End Try
 
    rgvDocumentsPO.DataSource = DataLayer.GetActiveDocumentsByDocTypeAndVendor(2, VendorID)
    rgvDocumentsDrawings.DataSource = DataLayer.GetActiveDocumentsByDocTypeAndVendor(3, VendorID)
 
    rgvDocumentsPO.Columns("Document ID").IsVisible = False
    rgvDocumentsDrawings.Columns("Document ID").IsVisible = False
 
    rgvDocumentsPO.Columns("Unconfirm").Width = 100
    rgvDocumentsDrawings.Columns("Unconfirm").Width = 100
 
    rgvDocumentsPO.BestFitColumns()
    rgvDocumentsDrawings.BestFitColumns()
 
End Sub
 
Any ideas on why this might be firing an error?

Thanks,
Chuck

2 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 19 Dec 2011, 09:53 AM
Hello Kawauser,

Thank you for contacting us.

From the code snippet I can conclude that you are adding the same GridViewCommandColumn in both grids. If this is true, this could be the reason for the issue. Grid columns are designed to be used in only one instance of RadGridView. I suggest that you create two instances of GridViewCommandColumn, one for every instance of RadGridView. If the issue continues to appear, please send us your application and we will investigate this issue in detail.

Looking forward to your reply.
 
All the best,
Jack
the Telerik team

Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

0
KawaUser
Top achievements
Rank 2
answered on 19 Dec 2011, 03:16 PM
That seems to have done the trick.

Now it looks like this.

Public Sub LoadDocuments(ByVal VendorID As Integer)
 
    Try
 
        Dim POCommandColumn As New GridViewCommandColumn
        POCommandColumn.Name = "Unconfirm"
        POCommandColumn.HeaderText = ""
        POCommandColumn.DefaultText = "Unconfirm"
        POCommandColumn.UseDefaultText = True
        POCommandColumn.TextAlignment = ContentAlignment.MiddleCenter
 
        Dim DocCommandColumn As New GridViewCommandColumn
        DocCommandColumn.Name = "Unconfirm"
        DocCommandColumn.HeaderText = ""
        DocCommandColumn.DefaultText = "Unconfirm"
        DocCommandColumn.UseDefaultText = True
        DocCommandColumn.TextAlignment = ContentAlignment.MiddleCenter
 
        If rgvDocumentsDrawings.RowCount = 0 Then
 
            rgvDocumentsDrawings.Columns.Add(POCommandColumn)
 
        End If
 
        If rgvDocumentsPO.RowCount = 0 Then
 
            rgvDocumentsPO.Columns.Add(DocCommandColumn)
 
        End If
 
    Catch ex As Exception
 
    End Try
 
    rgvDocumentsPO.DataSource = DataLayer.GetActiveDocumentsByDocTypeAndVendor(2, VendorID)
    rgvDocumentsDrawings.DataSource = DataLayer.GetActiveDocumentsByDocTypeAndVendor(3, VendorID)
 
    rgvDocumentsPO.Columns("Document ID").IsVisible = False
    rgvDocumentsDrawings.Columns("Document ID").IsVisible = False
 
    rgvDocumentsPO.Columns("Unconfirm").Width = 100
    rgvDocumentsDrawings.Columns("Unconfirm").Width = 100
 
    rgvDocumentsPO.BestFitColumns()
    rgvDocumentsDrawings.BestFitColumns()
 
End Sub


Thank you,
Chuck
Tags
GridView
Asked by
KawaUser
Top achievements
Rank 2
Answers by
Jack
Telerik team
KawaUser
Top achievements
Rank 2
Share this question
or