Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble using datagrid (or datagridview) in wpf or winform
    text
    copied!<p>I have a datagrid with small database (sql compact) Table contains more than 500 lines and each block contain different sections numbers;</p> <p>The Xamle code :</p> <pre><code> &lt;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"&gt; &lt;Grid&gt; &lt;Button Content="To TextBox" Height="29" HorizontalAlignment="Left" Margin="561,272,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" /&gt; &lt;DataGrid AutoGenerateColumns="True" Height="234" HorizontalAlignment="Left" Margin="12,12,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="644" /&gt; &lt;CheckBox Content="Section Rate" Height="16" HorizontalAlignment="Left" Margin="126,313,0,0" Name="checkBox1" VerticalAlignment="Top" /&gt; &lt;CheckBox Content="Section Result" Height="16" HorizontalAlignment="Left" Margin="28,313,0,0" Name="checkBox2" VerticalAlignment="Top" /&gt; &lt;CheckBox Content="Discipline" Height="16" HorizontalAlignment="Left" Margin="28,272,0,0" Name="checkBox3" VerticalAlignment="Top" /&gt; &lt;TextBox Height="54" HorizontalAlignment="Left" Margin="240,324,0,0" Name="textBox1" VerticalAlignment="Top" Width="396" /&gt; &lt;CheckBox Content="Total Biology" Height="16" HorizontalAlignment="Left" Margin="113,272,0,0" Name="checkBox4" VerticalAlignment="Top" /&gt; &lt;CheckBox Content="Math" Height="16" HorizontalAlignment="Left" Margin="28,351,0,0" Name="checkBox5" VerticalAlignment="Top" /&gt; &lt;CheckBox Content="Physics" Height="16" HorizontalAlignment="Left" Margin="113,351,0,0" Name="checkBox6" VerticalAlignment="Top" /&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>The Code behinde :</p> <pre><code>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(); } </code></pre> <p>I want to export the data to textbox1 based on selected checkbox, in this format : line 1 : Group Number , GroupName , Discipline( or Total Biology : Sum of results of rows in Biology Column) for each section number in selected Group Number : next lines : (Section Rate or Section Result , Math or Physics ) ==> based on selected checkbox</p> <p>for example : </p> <p>line 1 : 1,GPA,100(or 137= Total Biology) and if SectionResultcheckbox and mathchechbox is both checked : next lines will be :80 , 80, 90 ,70 ,54 ,31</p> <p>I have tried this :</p> <pre><code> DataRowView _data = dataGrid1.CurrentCell.Item as DataRowView; if (_data != null) { MessageBox.Show(_data.Row[0].ToString()); } </code></pre> <p>but it does not work.</p> <p>I do not know how to handle this issue ? thanks for any help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload