Datagrid : Data/Text not visible

Nov 17, 2008 at 3:59 AM
Edited Nov 17, 2008 at 5:15 AM

Hi,
After adding rows to datagrid using ITEMSOURCE or ITEM.ADD.... the data/text are not visible. It shows me empty rows.
Anyone to help me.
Regards.

Code goes like this :
Imports System.Collections.ObjectModel

 

Class Window1

 

 

 

Public Persons = New ObservableCollection(Of PersonName)

 

 

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click

 

 

Persons.Add(

New PersonName("Willa", "Cather"))

 

 

Persons.Add(

New PersonName("Isak", "Dinesen"))

 

 

Persons.Add(

New PersonName("Victor", "Hugo"))

 

 

Persons.Add(

New PersonName("Jules", "Verne"))

 

 

DataGrid1.ItemsSource = Persons

 

End Sub

 

 

End

 

Class

 

 

 

Coordinator
Nov 17, 2008 at 1:35 PM
What does the declaration of your DataGrid.Columns look like?
Nov 18, 2008 at 2:47 AM
Hi vinsibal,

Attached a sample WPF application. Can u do simple coding in VB or VC???

Thanks in advance,

sj_babu

http://www.4shared.com/file/71992224/4b81091f/Sample.html
Coordinator
Nov 18, 2008 at 1:43 PM
I'll start off with the first method and maybe you can get some ideas on how to implement the other ones:

Class

 

Window1

Private Persons As ObservableCollection(Of Person)

Public Sub New()
    InitializeComponent()
    Persons =
New ObservableCollection(Of Person)
    Me.DataGrid1.ItemsSource = Persons
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
    'Add NEW ROW with TEXT in TEXTBOX
    Dim temp As New Person
    temp.FirstName = TextBox1.Text
    temp.LastName = TextBox2.Text
    Me.Persons.Add(temp)
End Sub

 



Nov 19, 2008 at 5:43 AM
Edited Nov 19, 2008 at 6:00 AM
Hi vinsibal,

Thanks for your reply. Datagrid does not shows any text, it just adds empty rows.
I think we forgot column binding.
Can you please tell me on :
1. how to do column binding??
2. instead of PERSON CLASS can I use PERSON STRUCTURE (or any other simple collection)... how??
Example:
Private Structure Person
    Dim FirstName as string
    Dim LastName as string
End Structure

Private Persons as ObservableCollection(Of Person)
Persons = New ObservableCollection(Of Person)
Datagrid1.ItemsSource = Persons

Dim Temp as New Person
Temp.FirstName = TextBox1.Text
Temp.LastName = TextBox2.Text
Persons.Add(Temp)

I can't find the error!!!
Thanks in advance.