vendredi 20 octobre 2017

CheckBox click makrs anothers checkboxes on datagrid template C# WPF

This is an administrative program, i add bills on othe window and the i generate a groups of bills to make a check whit de sum of the bills i select a then ...

When i click on the second and the third one start to marks other check boxes in the datagrid... i all ready check in there´s a problem whith de code but i never conect de function whit the data grid

       <DataGrid.Columns>
                <DataGridTextColumn Header="id" Binding="{Binding id}"></DataGridTextColumn>
                <DataGridTextColumn Header="Proveedor" Binding="{Binding proveedor}"></DataGridTextColumn>
                <DataGridTextColumn Header="No de Factura" Binding="{Binding no_factura}"></DataGridTextColumn>
                <DataGridTextColumn Header="Total" Binding="{Binding total}"></DataGridTextColumn>
                <DataGridTextColumn Header="Fecha" Binding="{Binding fecha}"></DataGridTextColumn>
                <DataGridTextColumn Header="Cuenta" Binding="{Binding cuenta}"></DataGridTextColumn>

                <DataGridTemplateColumn Header="Accion">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox x:Name="check" Height="20" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked">
                                <CheckBox.RenderTransform>
                                    <TransformGroup>
                                        <ScaleTransform ScaleX="2" ScaleY="2"/>
                                        <SkewTransform/>
                                        <RotateTransform/>
                                        <TranslateTransform/>
                                    </TransformGroup>
                                </CheckBox.RenderTransform>
                            </CheckBox>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>

        </DataGrid>

Code

    private List<string> facts_ch = new List<string> { };
    private List<double> total_ch = new List<double> { };
    double total = 0;
    private DataTable dt =new DataTable();

    private void CheckBox_Checked(object sender, RoutedEventArgs e)
    {
        try {
            //MessageBox.Show(sender.ToString());
            DataRowView row = (DataRowView)((CheckBox)e.Source).DataContext;                
            string c = row[0].ToString();
            string[] a = {"No de Factura","Total","Proveedor" };
            double b = Convert.ToDouble(row[5]);
            if (dt.Columns.Count == 0)
            {
                for (int i = 0; i < 3; i++)
                    dt.Columns.Add(a[i]);
            }
            if (facts_ch.Contains(c))
            {     }
            else
            {
                DataRow dr = dt.NewRow();
                dr[0] = row[2].ToString();
                dr[1] = row[5].ToString();
                dr[2] = row[1].ToString();
                dt.Rows.Add(dr);
                facts_ch.Add(c);
                total_ch.Add(b);
                total = total + b;
            }
            dg_salida.ItemsSource = dt.AsDataView();

            //TextBox_1.Text = String.Join(Environment.NewLine, facts_ch);

            Total_tx.Text = total.ToString();

        } 
            catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }


    }




Aucun commentaire:

Enregistrer un commentaire