question

nachoshaw-9496 avatar image
0 Votes"
nachoshaw-9496 asked nachoshaw-9496 answered

Getting BindingSource Row by Column

Hey

I have a BindingSource on my form that collects data from a table. I am showing 3 columns out of 17 in a grid and need to capture the remaining 14 column values for a row. I can assign the BindingSource to a text box to display the specific value but how can i do it in code to save the values into a collection of properties?

I have tried this currently which is throwing an error (Cannot cast to type)

 ThermalBreak = directCast(ProjectDataBindingSource.Current, DataViewRow).Item("_thermal_break").ToString

i have also tried

 ThermalBreak = directCast(ProjectDataBindingSource.Current, DataViewRow).Item(0).ToString

Thanks


dotnet-standard
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @nachoshaw-9496 ,
What's the data source of your 'ProjectDataBindingSource' ?
Could you provide more related code here? It will help us analyze your question.

0 Votes 0 ·

1 Answer

nachoshaw-9496 avatar image
0 Votes"
nachoshaw-9496 answered

Hey

I figured it out. The DataSource to the ProjectDataBindingSource is a class, not a DataTable

 Imports System.ComponentModel
   
 Public Class ProjectData
    
     Public Property _job_id As String
     Public Property _name As String
     Public Property _thermal_break As String
    
     Public Sub New(ByVal job_id As Integer, ByVal name As String, ByVal thermalbreak As String)
    
         Dim ConvJobID As String = Convert.ToString(job_id.ToString("00000"))
    
         _job_id = ConvJobID
         _name = name
         _thermal_break = thermalbreak
    
     End Sub
    
     Public Shared Function GetProjectData() As BindingList(Of ProjectData)
         Dim JL As JOB.BLL.JobList = New JOB.BLL.JobList
         Dim GetList As List(Of JOB.BLL.JobList_details) = JL.GetJobListByAll()
    
         Dim List As BindingList(Of ProjectData) = New BindingList(Of ProjectData)
         For Each row As JOB.BLL.JobList_details In GetList
    
             List.Add(New ProjectData(row._job_id, row._name, row._thermal_break))
         Next
         Return List
    
     End Function
    
 End Class

Then in my form, i bind a Grid & some TextBoxes to the relavent BindingSourse fields.
Finally , to return the hidden column values in code, i use this

 Dim t As ProjectData = CType(projectDataBindingSource.Current, ProjectData)

Which provides access to the ProjectData members

 Dim _ID As String = t. _job_id
 Dim _Name As String = t._name
 Dim _TB As String = t._thermal_break

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.