A
Ash.22
Guest
Hello, I have been searching for 2 days with no luck. How do I assign the checked items of a checkedlistbox to a variable? So basically after choosing from the checkedlistbox I click on a button and it will be assigned to a variable then it will show in my dgv,
Here's my code:
CLASS FILE:
Public Class DealMetrics
Inherits ObjectBase
#Region " Properties "
Private _metrics As String
Public Property Metrics() As String
Get
Return _metrics
End Get
Set(ByVal value As String)
_metrics = value
End Set
End Property
#End Region
#Region " Data Access "
Protected Overrides ReadOnly Property Read As String
Get
' Updated the Select Query to bring back both Fields
Return "SELECT Metric from tblMetrics WHERE DealName = @DealName"
End Get
End Property
Public Function ReadMetrics() As List(Of DealMetrics)
Dim returnList As New List(Of DealMetrics)
Dim completeData As New DataSet
' Do your initial Read from the database.
Try
Using AConnString As New OleDb.OleDbConnection(ObjectBase.ConnectionString)
Using selectCommand As New OleDb.OleDbCommand(Read, AConnString)
selectCommand.Parameters.Add("@DealName", OleDb.OleDbType.VarChar, 80).Value = frmUpdateEdit.cmbDeals.Text
Using da As New OleDb.OleDbDataAdapter(selectCommand)
AConnString.Open()
da.Fill(completeData)
End Using
End Using
End Using
Catch ex As Exception
Throw
End Try
' Check to make sure some sort of Dataset is returned
If completeData.Tables.Count = 0 Then
Throw New Exception("No tables exist")
End If
' Loop through each row and return an object which has the Deals details Filled in.
For Each row As DataRow In completeData.Tables(0).Rows
returnList.Add(New DealMetrics(row))
Next
' return a list of your objects.
Return returnList
End Function
Public Sub New()
End Sub
Private Sub New(childData As DataRow)
' Load both properties from the Datarow
_metrics = childData.Field(Of String)("Metric")
End Sub
#End Region
End Class
FORM:
Private Sub frmUpdateEdit_Load(sender As Object, e As EventArgs) Handles MyBase.Load
GetDeals()
End Sub
#Region "Get Deals Details"
Private Sub GetDeals()
bgwDeals.RunWorkerAsync()
End Sub
Private Sub bgwDeals_DoWork(sender As Object, e As DoWorkEventArgs) Handles bgwDeals.DoWork
Dim pdeals As New DealNames()
_PDeals = pdeals.ReadDeals
End Sub
Private _PDeals As List(Of DealNames)
Private Sub bgwDeals_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles bgwDeals.RunWorkerCompleted
Try
Dim pdeals As New DealNames()
_PDeals = pdeals.ReadDeals
Me.bsrcDeals1.DataSource = _PDeals
GetMetrics()
Catch ex As Exception
MsgBox("ERROR : " & ex.Message.ToString)
Finally
End Try
End Sub
#End Region
#Region "Get Metrics Details"
Private Sub GetMetrics()
bgwMetrics.RunWorkerAsync()
End Sub
Private Sub bgwMetrics_DoWork(sender As Object, e As DoWorkEventArgs) Handles bgwMetrics.DoWork
Dim pMetrics As New DealMetrics
_PMetrics = pMetrics.ReadMetrics
End Sub
Private _PMetrics As List(Of DealMetrics)
Private Sub bgwMetrics_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles bgwMetrics.RunWorkerCompleted
Try
Dim pmetrics As New DealMetrics()
_PMetrics = pmetrics.ReadMetrics
Me.bsrcMetrics.DataSource = _PMetrics
Me.chklMetrics.DataSource = _PMetrics
Me.chklMetrics.DisplayMember = "Metrics"
Catch ex As Exception
MsgBox("ERROR : " & ex.Message.ToString)
Finally
End Try
End Sub
#End Region
Please help I'm at my wit's end thank you
Continue reading...
Here's my code:
CLASS FILE:
Public Class DealMetrics
Inherits ObjectBase
#Region " Properties "
Private _metrics As String
Public Property Metrics() As String
Get
Return _metrics
End Get
Set(ByVal value As String)
_metrics = value
End Set
End Property
#End Region
#Region " Data Access "
Protected Overrides ReadOnly Property Read As String
Get
' Updated the Select Query to bring back both Fields
Return "SELECT Metric from tblMetrics WHERE DealName = @DealName"
End Get
End Property
Public Function ReadMetrics() As List(Of DealMetrics)
Dim returnList As New List(Of DealMetrics)
Dim completeData As New DataSet
' Do your initial Read from the database.
Try
Using AConnString As New OleDb.OleDbConnection(ObjectBase.ConnectionString)
Using selectCommand As New OleDb.OleDbCommand(Read, AConnString)
selectCommand.Parameters.Add("@DealName", OleDb.OleDbType.VarChar, 80).Value = frmUpdateEdit.cmbDeals.Text
Using da As New OleDb.OleDbDataAdapter(selectCommand)
AConnString.Open()
da.Fill(completeData)
End Using
End Using
End Using
Catch ex As Exception
Throw
End Try
' Check to make sure some sort of Dataset is returned
If completeData.Tables.Count = 0 Then
Throw New Exception("No tables exist")
End If
' Loop through each row and return an object which has the Deals details Filled in.
For Each row As DataRow In completeData.Tables(0).Rows
returnList.Add(New DealMetrics(row))
Next
' return a list of your objects.
Return returnList
End Function
Public Sub New()
End Sub
Private Sub New(childData As DataRow)
' Load both properties from the Datarow
_metrics = childData.Field(Of String)("Metric")
End Sub
#End Region
End Class
FORM:
Private Sub frmUpdateEdit_Load(sender As Object, e As EventArgs) Handles MyBase.Load
GetDeals()
End Sub
#Region "Get Deals Details"
Private Sub GetDeals()
bgwDeals.RunWorkerAsync()
End Sub
Private Sub bgwDeals_DoWork(sender As Object, e As DoWorkEventArgs) Handles bgwDeals.DoWork
Dim pdeals As New DealNames()
_PDeals = pdeals.ReadDeals
End Sub
Private _PDeals As List(Of DealNames)
Private Sub bgwDeals_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles bgwDeals.RunWorkerCompleted
Try
Dim pdeals As New DealNames()
_PDeals = pdeals.ReadDeals
Me.bsrcDeals1.DataSource = _PDeals
GetMetrics()
Catch ex As Exception
MsgBox("ERROR : " & ex.Message.ToString)
Finally
End Try
End Sub
#End Region
#Region "Get Metrics Details"
Private Sub GetMetrics()
bgwMetrics.RunWorkerAsync()
End Sub
Private Sub bgwMetrics_DoWork(sender As Object, e As DoWorkEventArgs) Handles bgwMetrics.DoWork
Dim pMetrics As New DealMetrics
_PMetrics = pMetrics.ReadMetrics
End Sub
Private _PMetrics As List(Of DealMetrics)
Private Sub bgwMetrics_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles bgwMetrics.RunWorkerCompleted
Try
Dim pmetrics As New DealMetrics()
_PMetrics = pmetrics.ReadMetrics
Me.bsrcMetrics.DataSource = _PMetrics
Me.chklMetrics.DataSource = _PMetrics
Me.chklMetrics.DisplayMember = "Metrics"
Catch ex As Exception
MsgBox("ERROR : " & ex.Message.ToString)
Finally
End Try
End Sub
#End Region
Please help I'm at my wit's end thank you
Continue reading...