Home Forums WPF controls Xceed DataGrid for WPF WPF datagrid – Bind Generic Lists

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22897 |

    Hi,

    I tried to bind a generic list to wpf datagrid but it didn’t worked: dataGrid.DataContext = DataGateway.SelectAll<Users>();

    The columns appeared but no data in it.

    What do I need to do?

    Thanks
    Gavrilovici Corneliu

    Imported from legacy forums. Posted by Gavrilovici (had 3115 views)

    Xceed Support
    Member
    Post count: 5658

    Can you share a little more of your code:

    XAML or C# code that initialize the DataGridControl, the Columns, …

    Imported from legacy forums. Posted by Marcus [Xceed] (had 253 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello. I have a similar problem with binding the WPF datagrid to a generic list. I have a static class with methods to manipulate the database:

    public static class DatabaseAccess
    {
    public static List<Organization> GetAllOrganizations()
    {
    // get all organizations from the database
    }


    }

    As is suggested above, this – DataContext=”DatabaseAccess.GetAllOrganizations” – does not display any rows in the grid. The only way I was able to make t work was the one described in the documentation, i.e.:

    public partial class App : System.Windows.Application
    {
    protected override void OnStartup(StartupEventArgs e)
    {
    Xceed.Wpf.DataGrid.Licenser.LicenseKey = “some valid code”;
    base.OnStartup(e);
    }

    public List<Organization> Organizations
    {
    get
    {
    return DatabaseAccess.GetAllOrganizations();
    }
    }
    }

    And then: ItemsSource=”{Binding Source={x:Static Application.Current}, Path=Organizations}

    But I must say this is unacceptable for me because I’d have to stuff the App class with properties for each method of the DatabaseAccess class. Are there no means to point to the data source directly, without creating such properties?

    Imported from legacy forums. Posted by Dimitar (had 660 views)

    User (Old forums)
    Member
    Post count: 23064

    I am very sorry, I guess I was in too much hurry. I turned out to be extremely easy:

    this.gridOrganizations.ItemsSource = DatabaseAccess.GetAllOrganizations();

    Still, I’d be thankful if I knew how to write the above statement in the XAML code instead. Thanks in advance.

    Imported from legacy forums. Posted by Dimitar (had 4273 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.