Silverlight datagrid.itemssource display problem...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BbEsy
    New Member
    • Sep 2009
    • 28

    Silverlight datagrid.itemssource display problem...

    Hello all I new in silverlight And i found one strange thing..

    when i tried to bind List of object to datagrid all works fine. Values shows fine... But, when i try to use linq to select only one value. Datagrid return blanks rows..

    but what is strange. where i try to get value of selected row it gives me right value...
    here is code

    Code:
    private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
            {
                List<test> lTest = new List<test>();
                lTest.Add(new test("test", "test2"));
                lTest.Add(new test("test", "test2"));
                //dataGrid1.ItemsSource = lTest; this Works
                dataGrid1.ItemsSource = from t in lTest select new { val1 = t.Value1 };
            }
        }
    
        public class test
        {
            public test(string Value1, string Value2)
            {
                this.Value1 = Value1; 
                this.Value2 = Value2;
            }
            public string Value1 { get; set; }
            public string Value2 { get; set; }
        }
    can anybody tell me where is problem ?
  • ThatThatGuy
    Recognized Expert Contributor
    • Jul 2009
    • 453

    #2
    Code:
       dataGrid1.ItemsSource = from t in lTest select new { val1 = t.Value1 };
    So this portion of the code doesn't work.

    I don't think the items source property works best with anonymous types.
    You need to specify an object type.

    Just imagine. how will you get the selected item in the datagrid, if its holding a collection of anonymous types.

    Comment

    • BbEsy
      New Member
      • Sep 2009
      • 28

      #3
      if i try this in WPF application all works fine... Then somewhere must be a problem...

      btw.: In any case you dont need to get selected item in datagrid, because you only need to display values..

      Comment

      Working...