在silverlight中,点击dataGrid 中的行,能自动在下面的textBox显示对应的数据。。求指导
展开全部
//采纳我的把 Thanks!
//后台代码
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
TestData testData1 = new TestData() { Name = "jason", Description = "test" };
TestData testData2 = new TestData() { Name = "yang", Description = "test1" };
List<TestData> testDatas = new List<TestData>();
testDatas.Add(testData1);
testDatas.Add(testData2);
this.dgTest.ItemsSource = testDatas;
this.dgTest.SelectedIndex = 0;
}
private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
DataGrid dataGrid = sender as DataGrid;
TestData testData = dataGrid.SelectedItem as TestData;
this.tbName.Text = testData.Name;
}
}
public class TestData
{
public string Name { get; set; }
public string Description { get; set; }
public TestData()
{
}
}
//XAML
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="191*" />
<RowDefinition Height="120*" />
</Grid.RowDefinitions>
<DataGrid Name="dgTest" SelectionChanged="DataGrid_SelectionChanged" ></DataGrid>
<TextBox Grid.Row="1" x:Name="tbName" Width="200" Height="30"></TextBox>
</Grid>
//后台代码
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
TestData testData1 = new TestData() { Name = "jason", Description = "test" };
TestData testData2 = new TestData() { Name = "yang", Description = "test1" };
List<TestData> testDatas = new List<TestData>();
testDatas.Add(testData1);
testDatas.Add(testData2);
this.dgTest.ItemsSource = testDatas;
this.dgTest.SelectedIndex = 0;
}
private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
DataGrid dataGrid = sender as DataGrid;
TestData testData = dataGrid.SelectedItem as TestData;
this.tbName.Text = testData.Name;
}
}
public class TestData
{
public string Name { get; set; }
public string Description { get; set; }
public TestData()
{
}
}
//XAML
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="191*" />
<RowDefinition Height="120*" />
</Grid.RowDefinitions>
<DataGrid Name="dgTest" SelectionChanged="DataGrid_SelectionChanged" ></DataGrid>
<TextBox Grid.Row="1" x:Name="tbName" Width="200" Height="30"></TextBox>
</Grid>
展开全部
你listbox里面有selecitem事件吧 你用这个 然后再sender里面取到相应的数据 再给姓名的textblock 就可以了 多么简单
追问
初学呀,有selectitem呀,但是不知道怎样sender,能给点代码不?我的dataGrid里面的数据是用domain server 绑定的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
做事件处理,然后在事件中把你查询的数据绑定到textbox。
追问
具体点,给点代码,十分感谢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询