我有一个带有小型数据库(sql compact)的数据网格表包含超过 500 行,每个块包含不同的部分编号;
Xamle 代码:
<Window x:Class="WpfApplication9.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="440" Width="690" Loaded="Window_Loaded">
<Grid>
<Button Content="To TextBox" Height="29" HorizontalAlignment="Left" Margin="561,272,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
<DataGrid AutoGenerateColumns="True" Height="234" HorizontalAlignment="Left" Margin="12,12,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="644" />
<CheckBox Content="Section Rate" Height="16" HorizontalAlignment="Left" Margin="126,313,0,0" Name="checkBox1" VerticalAlignment="Top" />
<CheckBox Content="Section Result" Height="16" HorizontalAlignment="Left" Margin="28,313,0,0" Name="checkBox2" VerticalAlignment="Top" />
<CheckBox Content="Discipline" Height="16" HorizontalAlignment="Left" Margin="28,272,0,0" Name="checkBox3" VerticalAlignment="Top" />
<TextBox Height="54" HorizontalAlignment="Left" Margin="240,324,0,0" Name="textBox1" VerticalAlignment="Top" Width="396" />
<CheckBox Content="Total Biology" Height="16" HorizontalAlignment="Left" Margin="113,272,0,0" Name="checkBox4" VerticalAlignment="Top" />
<CheckBox Content="Math" Height="16" HorizontalAlignment="Left" Margin="28,351,0,0" Name="checkBox5" VerticalAlignment="Top" />
<CheckBox Content="Physics" Height="16" HorizontalAlignment="Left" Margin="113,351,0,0" Name="checkBox6" VerticalAlignment="Top" />
</Grid>
背后的代码:
private void button1_Click(object sender, RoutedEventArgs e)
{
DataRowView _data = dataGrid1.CurrentCell.Item as DataRowView;
if (_data != null)
{
MessageBox.Show(_data.Row[0].ToString());
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
SqlCeConnection con = new SqlCeConnection(@"Data Source=C:\MyDatabase1.sdf");
con.Open();
SqlCeDataAdapter da = new SqlCeDataAdapter("select * from StudentGroup", con);
DataTable dt = new DataTable();
DataSet ds = new DataSet();
da.Fill(dt);
dataGrid1.ItemsSource = dt.DefaultView;
//dataGrid1.ItemsSource = ds.Tables[0].DefaultView;
con.Close();
}
我想根据选定的复选框将数据导出到 textbox1,格式如下:第 1 行:组号、组名、学科(或总生物学:生物学列中行结果的总和)对于所选组号中的每个节号:下一个行:(部分速率或部分结果,数学或物理)==> 基于选中的复选框
例如 :
第 1 行:1,GPA,100(或 137= Total Biology)如果 SectionResultcheckbox 和 mathchechbox 都被选中:下一行将是 :80 , 80, 90 ,70 ,54 ,31
我试过这个:
DataRowView _data = dataGrid1.CurrentCell.Item as DataRowView;
if (_data != null)
{
MessageBox.Show(_data.Row[0].ToString());
}
但它不起作用。
我不知道如何处理这个问题?谢谢你的帮助。