我有一個小型數據庫(sql compact)的數據網格 表包含500多行,每個塊包含不同的節號;在wpf或winform中使用datagrid(或datagridview)時遇到問題
的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>
守則behinde:
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 :組號,組名,學科(或生物學總數:生物學專欄中的行結果總和) 對於選定G中的每個片段編號roup編號: 下一行:(第速率或段的結果,數學或物理)==>基於選擇的複選框
例如:
線1:1,GPA,100(或137 =總生物學) 如果SectionResultcheckbox和mathchechbox既是檢查: 下一行會:80,80,90,70,54,31
我已經試過這樣:
DataRowView _data = dataGrid1.CurrentCell.Item as DataRowView;
if (_data != null)
{
MessageBox.Show(_data.Row[0].ToString());
}
,但它不工作。
我不知道如何處理這個問題? 感謝您的任何幫助。
是什麼問題?什麼不工作?你有什麼麻煩?如果不知道病情,就不能給予藥物:) – Ehsan
@沒有人:我已經解釋了:我想根據選中的複選框將數據導出到textbox1,格式如下:第1行:組號,組名,學科(或總數生物學:生物學專欄中的行結果總和)以及選定組編號中的每個分節編號:下一行:(分節速率或分節結果,數學或物理)==>基於選定的複選框 –
@SmartMan當「 Discipline' checkbox is checked?...應該輸出什麼? – Rohit