list all fields/coloumns in bindingsource and add them to unbound datagridview vb.net

Hi I want to list all fields/coloumns in bindingsource and add them to unbound datagridview.
I have a unbound datagridview and set out how I want it to look. I quite new to programing so please show in detail.

Iam using
TempBindingSource
DataGridView1
LVL 3
taz8020Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Coralie CrumrineCommented:
What I did was create a function to format the datagridview column:

Public Function SetDViewTextBoxColumn(ByRef objSrc As DataGridViewTextBoxColumn, ByVal szMappingName As String, ByVal szHeaderText As String, ByVal lWidth As Int32, Optional ByVal lAutoSizeMode As DataGridViewAutoSizeColumnMode = DataGridViewAutoSizeColumnMode.Fill, Optional ByVal szFormat As String = "", Optional ByVal lAlignment As DataGridViewContentAlignment = DataGridViewContentAlignment.MiddleCenter, Optional ByVal szNullText As String = "", Optional ByVal blIsVisible As Boolean = True, Optional ByVal blIsReadonly As Boolean = False) As DataGridViewTextBoxColumn
        With objSrc
            .Name = szMappingName
            .DataPropertyName = szMappingName

            If szHeaderText <> "" Then
                .HeaderText = szHeaderText
            Else
                .HeaderText = szMappingName
            End If

            If szFormat <> "" Then
                .DefaultCellStyle.Format = szFormat
            End If

            .DefaultCellStyle.Alignment = lAlignment
            .DefaultCellStyle.NullValue = szNullText
            .Width = lWidth
            .Visible = blIsVisible
            .AutoSizeMode = lAutoSizeMode
            .ReadOnly = blIsReadonly
        End With

        Return objSrc
        'If Not objTableStyle Is Nothing Then objTableStyle.GridColumnStyles.Add(objSrc)
    End Function




then assign which columns out of the table I want to show

            dgvView.Columns.Clear()

            dgvView.AutoGenerateColumns = False
            dgvView.DataSource = tbl

            Dim dvColDateVisit As New DataGridViewTextBoxColumn
            dgvView.Columns.Add(SetDViewTextBoxColumn(dvColDateVisit, "DateVisit", "Date Visit", 75, , "d", DataGridViewContentAlignment.MiddleRight))
dgView.Refresh



I hope that this helps. Let me know if you have any questions or this does not work for you.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CodeCruiserCommented:
What is the datasource of the binding source? Is it a datatable?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.