HighTechTalks DotNet Forums  

Simple DGV binding to List(Of String), String(), Collection, etc??

Dotnet Framework (WinForms DataBinding) microsoft.public.dotnet.framework.windowsforms.databinding


Discuss Simple DGV binding to List(Of String), String(), Collection, etc?? in the Dotnet Framework (WinForms DataBinding) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
TBQ
 
Posts: n/a

Default Simple DGV binding to List(Of String), String(), Collection, etc?? - 11-01-2007 , 01:31 PM






Sorry for the repost, but according to MS, it is required (in order to get a
reply)... :-<



I'm trying to do something very simple - display an editable list of strings
in a DataGridView (2.0). When I try to simply bind to the DGV, it displays
the LENGTH of my strings instead of the contents. The same thing happens if
I bind to an Array of strings:

Dim newList As New List(Of String)
newList.Add("Line One")
newList.Add("Line 2")
newList.Add("Ln Three")
Me.DataGridView1.DataSource = newList
or
Me.DataGridView1.DataSource = New String() {"xyz", "abc"}

Using a BindingList or a traditional Collection doesn't make a difference
either.

In each of these cases AFAICT, the supplied Data Sources do implement one or
more of the ones indicated as supported by the DGV. I guess it doesn't state
that it will provide MEANINGFUL binding, but... :->

*What am I missing?*

I know the value of a String type is not a property of the String Class, but
please... Do we *have* to *cross* the river just to get some water?

I can make it work by creating a dummy object to hold my strings, but that
seems like a Mickey Mouse solution:

Public Class DoTextList
Public Sub New(ByVal value As String)
MyText = value
End Sub
Private MyText As String
Public Property Text() As String
Get
Return MyText
End Get
Set(ByVal value As String)
MyText = value
End Set
End Property
End Class

Public Class Form1

Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGridView1.Click
Dim newList As New List(Of DoTextList)
newList.Add(New DoTextList("Line One"))
newList.Add(New DoTextList("Line 2"))
newList.Add(New DoTextList("Ln Three"))
Me.DataGridView1.DataSource = newList
End Sub
End Class



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.