Databind DataGridView to List(of String)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?aGVyYmVydA==?=

    Databind DataGridView to List(of String)

    I use the following code to programmaticall y bind a DataGridView and a
    BindingNavigato r to various List(of myClass). This works fine with each
    'myClass' offering public properties.

    Dim mAllUsers As List(Of myClass)
    mAllUsers = GetAllUsers() 'returns List(Of myClass)
    Dim AllUsersBinding Source As New BindingSource(M e.components)
    ControlStationI nfoBindingNavig ator.BindingSou rce = AllUsersBinding Source
    ControlStationI nfoDataGridView .AutoGenerateCo lumns = True
    ControlStationI nfoDataGridView .DataSource = AllUsersBinding Source
    AllUsersBinding Source.DataSour ce = mAllUsers

    If I change the code to
    Dim mAllUsers As List(Of String)
    mAllUsers = GetAllUsers() 'returns List(Of String)
    then the DataGridView only displays one column containing the length of each
    string.

    I want only to display the strings in one column.

    thank you very much, herbert

  • RobinS

    #2
    Re: Databind DataGridView to List(of String)

    You could try using a BindingList(of whatever) instead of a List. It has all
    the inherent properties needed to bind a list to a binding list and thus to
    a control.

    RobinS.
    GoldMail.com

    "herbert" <herbert@discus sions.microsoft .comwrote in message
    news:5AF2E876-2F6A-46F3-A14A-39EC99F97B20@mi crosoft.com...
    >I use the following code to programmaticall y bind a DataGridView and a
    BindingNavigato r to various List(of myClass). This works fine with each
    'myClass' offering public properties.
    >
    Dim mAllUsers As List(Of myClass)
    mAllUsers = GetAllUsers() 'returns List(Of myClass)
    Dim AllUsersBinding Source As New BindingSource(M e.components)
    ControlStationI nfoBindingNavig ator.BindingSou rce = AllUsersBinding Source
    ControlStationI nfoDataGridView .AutoGenerateCo lumns = True
    ControlStationI nfoDataGridView .DataSource = AllUsersBinding Source
    AllUsersBinding Source.DataSour ce = mAllUsers
    >
    If I change the code to
    Dim mAllUsers As List(Of String)
    mAllUsers = GetAllUsers() 'returns List(Of String)
    then the DataGridView only displays one column containing the length of
    each
    string.
    >
    I want only to display the strings in one column.
    >
    thank you very much, herbert
    >

    Comment

    Working...