i have bounded a dataset to a listbox and i want to get the selected values when i clicked add and write them to a text box. here is the code i'v used
Expand|Select|Wrap|Line Numbers
- Imports System.Data.SqlClient
- Public Class frmContactList
- Private conContacts As SqlConnection
- Private cmdContacts As SqlCommand
- Private dtaContacts As SqlDataAdapter
- Private dtsContacts As DataSet
- Private Sub frmContactList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
- txtNumberList.Text = frmSendSMS.txtTo.Text
- conContacts = New SqlConnection("Data Source=localhost;Initial Catalog=ABC;Integrated Security=True")
- cmdContacts = New SqlCommand("SELECT ('<' + PHONE_MOBILE + '> ' + TITLE + '. ' + F_NAME + ' ' + L_NAME) AS NAME, PHONE_MOBILE AS MOBILE FROM CONTACTS", conContacts)
- dtaContacts = New SqlDataAdapter
- dtsContacts = New DataSet
- dtaContacts.SelectCommand = cmdContacts
- Try
- conContacts.Open()
- dtaContacts.Fill(dtsContacts, "CONTACTS")
- Catch ex As Exception
- MessageBox.Show(ex.Message.ToString)
- Finally
- conContacts.Close()
- End Try
- lstContacts.DataSource = dtsContacts.Tables("CONTACTS")
- lstContacts.DisplayMember = "NAME"
- lstContacts.ValueMember = "MOBILE"
- End Sub
- Private Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelect.Click
- frmSendSMS.txtTo.Text = txtNumberList.Text
- Me.Close()
- End Sub
- Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click, lstContacts.DoubleClick
- For i As Integer = 0 To lstContacts.Items.Count - 1
- If lstContacts.Items(i).Selected Then 'Error comes here
- txtNumberList.Text += lstContacts.Items(i).Text & ";"
- End If
- Next
- End Sub
- Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
- txtNumberList.Text = ""
- End Sub
- End Class
Error:
Missing Member Exception was unhandled
Public member 'Selected' on type 'DataRowView' not found.
please tell me how to fix this or is their a better way to do this?
chathura