views:

21

answers:

2

i am doing this xaml :

 <StackPanel Margin="320,0,0,0" Grid.RowSpan="2">
        <ListView ItemsSource="{Binding employeeCollection}">
            <ListView.View>
                <GridView>

                    <GridViewColumn Header="Employee ID" DisplayMemberBinding="{Binding Path=EmployeeID}"/>
                    <GridViewColumn Header="First Name" DisplayMemberBinding="{Binding Path=FirstName}"/>
                    <GridViewColumn Header="Last Name" DisplayMemberBinding="{Binding Path=LastName}"/>
                    <GridViewColumn Header="start" DisplayMemberBinding="{Binding Path=startHR}"/>
                    <GridViewColumn Header="finish" DisplayMemberBinding="{Binding Path=finishHR}">

                </GridViewColumn>
            </GridView>
    </ListView.View>

        </ListView>
    </StackPanel>

and the code behind is :

class employeesGrid //: INotifyPropertyChanged
{
    ObservableCollection<employiesData> _employeeCollection = 
    new ObservableCollection<employiesData>();

    public employeesGrid()
{
    _employeeCollection.Add(new employiesData{

      EmployeeID = "World Of Warcraft", 
      FirstName = "Blizzard", 
      LastName = "Blizzard",
      startHR = "2222",
      finishHR = "dfs"
  });


}

    public ObservableCollection<employiesData> employeeCollection
{ get { return _employeeCollection; } }


}

public class employiesData
{
    public string EmployeeID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string startHR { get; set; }
    public string finishHR { get; set; }
}

}

where inside my main window i am doing :

//constructor: InitializeComponent(); employeesGrid em = new employeesGrid();

1.can someone please guide me what am i doing wrong ? 2.INotifyPropertyChanged why should i use it ? how should i use it ?

thanku for gazing in my work it means a lot to me :)

lets say i want two sturctures like this in my program what would be the best implmantion ????

+1  A: 

You never set your listviews' DataContext.

Try this in your window constructor:

InitializeComponent(); 
employeesGrid em = new employeesGrid();
this.DataContext = em;
Kai Wang
yes the problem is DataContext = vm //vm is class ConnectionViewModel : INotifyPropertyChangedso how i make them live togther what should be the archtcture ?
yoav.str
@yoav.str, the employeeCollection property should be exposed through ConnectionViewModel class. In the getter you can simply return employeesGrid.employeeCollection if you have to keep two classes instead merge them into one.
Kai Wang
mmm meaning connectionHandler hm whom support number of collection ?is there better archticture ? or any example how to do it as simple/pro as it get ?
yoav.str
+1  A: 
  1. You need to bind your view's datasource to your class instance. In your constructor, do this: this.DataContext = new employeesGrid();
  2. INotifyPropertyChanged is an interface that you should use if you want your UI to refresh it's content when the underlying content changes.
OJ