Click here to Skip to main content
15,991,287 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
wpf How can Get index selected items in datagridcomboboxcolumns from datagridview
Please Fast Reply........
Posted
Updated 11-Mar-14 21:16pm
v2
Comments
[no name] 12-Mar-14 8:17am    
Actually ur Problem Is Very Big.....
[no name] 12-Mar-14 8:18am    
???????????????????????????

1 solution

Hi,

The simplest way is as following:

MainWindow.cs:

XML
<Grid>
    <DataGrid x:Name="grid" ItemsSource="{Binding Items}" SelectionChanged="DataGrid_SelectionChanged"/>
</Grid>


Code behind:

C#
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    
        this.DataContext = this;
    
        var list = new List<Data>();
    
        for (int i = 0; i < 10; i++)
        {
           list.Add(new Data() { FirstName = "First " + i, 
                                 LastName = "Last " + i });
        }
    
        this.Items = list;
    }
    
    public IEnumerable Items
    {
        get;
        set;
    }
    
    void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
       var selected = grid.SelectedItems;
    }
}

public class Data
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900