wpf linq绑定datagrid后怎么获取某行某列的值
1个回答
展开全部
既然是绑定,那么就通过数据源获取就好了。
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private List<Test> list = new List<Test>();
private List<Test> list_s;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
list.AddRange(new Test[] { new Test { Title = "1" }, new Test { Title = "2" }, new Test { Title = "3" } });
//*****************
list_s = (from l in list select l).ToList();
this.datagrid.ItemsSource = list_s;
MessageBox.Show(list_s[2].Title);
}
}
public class Test
{
public string Title
{
get { return this.title; }
set { this.title = value; }
}
private string title = string.Empty;
}
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private List<Test> list = new List<Test>();
private List<Test> list_s;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
list.AddRange(new Test[] { new Test { Title = "1" }, new Test { Title = "2" }, new Test { Title = "3" } });
//*****************
list_s = (from l in list select l).ToList();
this.datagrid.ItemsSource = list_s;
MessageBox.Show(list_s[2].Title);
}
}
public class Test
{
public string Title
{
get { return this.title; }
set { this.title = value; }
}
private string title = string.Empty;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询