我有一个文本框,你输入一个数字,这个工程。WPF从datagrid获取数据东西存储过程
我有一个数据网格,从MSSQL数据库中利用基于文本框中编号的存储过程提取数据,这是有效的。
现在我想单击一行并将数据库中的特定值写入消息箱,但这不起作用。
这里是代码:
文本框:
private void TextChanged(object sender, TextChangedEventArgs e)
{
int parsedValue;
if (!int.TryParse(textBox.Text, out parsedValue))
{
return;
}
int a = Convert.ToInt32(textBox.Text);
dataGrid1.ItemsSource = context.GetRapport3(a);
}
数据网格:
private void MouseDC(object sender, MouseButtonEventArgs e)
{
if (dataGrid1.SelectedItem == null)
{
return;
}
var Selected = dataGrid1.SelectedItem;
MessageBox.Show(string.Format("You have chosen: {0}", Selected));
}
的XAML:
<Window x:Class="NolekRapport.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:NolekRapport"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Grid>
<DataGrid x:Name="dataGrid1" HorizontalAlignment="Left" Margin="83,104,0,0" VerticalAlignment="Top" MouseDoubleClick="MouseDC" />
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="83,65,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="120" TextChanged="TextChanged"/>
<Label x:Name="label" Content="Search:" HorizontalAlignment="Left" Margin="19,65,0,0" VerticalAlignment="Top"/>
</Grid>
也有是这样的:
DataClasses1DataContext context = new DataClasses1DataContext();
问题是,当我运行一个行程序,点击我得到这个消息框:
You have chosen: CompanyRapport.GetRapport3Result
GetRapport3是存储过程我用的名字找到数据来填充数据网格。我想只是从特定的单元格中获取值。
我对整个WPF(真正的编码作为一个整体)都很新,所以请简单说明一下。感谢您的时间和耐心。
编辑:
基本上输出是完全一样的,不管什么单元行点击/上。它始终是“CompanyRapport.GetRapport3Result”。我希望它是来自数据库中特定表的特定属性,或者是单击单元格中的至少一个值。