Skale
asked on
How to get checked items from dialog's listview in vb.net
Hello I'm using below code to get checked items but it gives "Object reference not set to instance of object" error. Does anyone knows how can i fix that?
and this is entire class of dialog
Try
If BuildSetLabelID.ShowDialog() = DialogResult.OK Then
Dim id As String = BuildSetLabelID.cboSetID.SelectedItem.ToString
For Each i As ListViewItem In BuildSetLabelID.lstDataGridViews.CheckedItems
MsgBox(i.Name)
Next
End If
Catch ex As Exception
Tools.OutputLog.Print(Tools.OutputLog.Type.ERR, ex.Message)
End Try
and this is entire class of dialog
Public Class BuildSetLabelID
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
End Sub
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Close()
End Sub
Private Sub DialogLoad(sender As Object, e As EventArgs) Handles MyBase.Load
lstDataGridViews.Clear()
FindDataGridViews(GUI.pnlModuleBuildContent)
End Sub
Private Sub FindDataGridViews(ByVal control As Control)
If control.HasChildren Then
For Each childControl As Control In control.Controls
If (TypeOf (childControl) Is DataGridView) Then
Dim dgv As DataGridView = CType(childControl, DataGridView)
If dgv.Columns.Contains("colKey") = True Then
Dim item As New ListViewItem With {
.Text = dgv.Tag,
.Tag = dgv.Name
}
lstDataGridViews.Items.Add(dgv.Tag)
End If
Else
FindDataGridViews(childControl)
End If
Next
End If
End Sub
End Class
Which line gives the error?
ASKER
After i clicked OK button it gives this error.
This part:
This part:
If BuildSetLabelID.ShowDialog() = DialogResult.OK Then
Dim id As String = BuildSetLabelID.cboSetID.SelectedItem.ToString
For Each i As ListViewItem In BuildSetLabelID.lstDataGridViews.CheckedItems
MsgBox(i.Name)
Next
End If
Which line is throwing the error? Can you show the full error dialog (take a screenshot)??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.