|
-
Nov 21st, 2003, 06:08 AM
#1
Thread Starter
Lively Member
Count clicks in listbox
I'm trying to detect if a user has clicked an item in a listbox. The reason for this is that if a user has clicked the listbox, then the datasettable that fills the second listbox must be cleared and filled up by another dataadapter.
I've written some code but is doesnt do the job:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
If blnLoadListbox1 = True Then
Dim strSQLGroup As String
If Me.ListBox1.SelectedIndex > -1 Then
Me.dataset.Tables("tblGroup").Clear()
End If
Try
strSQLGroup = "SELECT GroupDescription FROM tblGroup where tblGroup.MainGroupID=" & Me.ListBox1.SelectedValue.ToString
Dim DAGroup As OleDbDataAdapter = New OleDbDataAdapter(strSQLGroup, connection)
DAGroup.Fill(dataset, "tblGroup")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Me.ListBox2.DataSource = dataset.Tables("tblGroup")
Me.ListBox2.DisplayMember = "GroupDescription"
End If
End Sub
The code crashes and I get an error message at the line : Me.dataset.Tables("tblGroup").Clear(). The message is the following:
An unhandled exception of type 'System.NullReferenceException' occurred in TypedDatasets.exe
Additional information: Object reference not set to an instance of an object.
Any ideas???
Thanks
Tom
Last edited by zozzie; Nov 21st, 2003 at 07:21 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|