Columns and row datagrid wpf

3

I have an editable datagrid in wpf, when writing in a cell it puts that same value in the cell that follows, in the same row, but when I have another row the value of my cell in the second row paints it in the cell next from the first row, how can I do to paint the same value on the same row, attached image and code of what I have.

private void cuenta_LostFocus(object sender, RoutedEventArgs e)
    {

        MaskedTextBox t2 = (MaskedTextBox)e.Source;

        string tex2 = t2.Text;

        try
        {
            var row_list = GetDataGridRows(Grd_Detalle_Provision); //metodo para obtener las filas de mi grid detalle_provision

            foreach (DataGridRow single_row in row_list) // recorro las filas que tiene el grid
            {



            if (single_row.IsSelected == true) // si al fila esta seleccionada 
            {
                TextBox t = FindChild<TextBox>(Grd_Detalle_Provision, "txt_nomCuenta"); // busco el texblock llamado txt_cuentaen el grid
                t.Text = tex2; // asigno lo que trae mi celda de numero de cuenta al texbox de nombre de la cuenta
            }

            }
        }

        catch
        {
            throw new Exception("Can't get access to DataGridRow");
        }
    }
    
asked by Cesar Ramirez Monroy 03.06.2016 в 00:07
source

2 answers

0

from the XAML code, you can have the value assigned to a specific control, by means of a Binding.

<TextBox x:Name = "txtOriginal">
<TextBox Text= "{Binding ElementName=txtOriginal, Path=Text}">

If you want to know more about Binding in WPF, here are a couple of links.

Information about Binding 1

Microsoft Developer Network information

    
answered by 02.11.2016 в 20:07
0

C # and WPF use Bindings to establish relationships between views and controls that are updated diamically. You can use them by following the following tutorial, with a simple logic you can persist those results to the source from which you took them.

In the following tutorial the bindings with DataGrids are explained

link

It would be something like this:

// Código
public Info{
  return GetDataGridRows(Grd_Detalle_Provision);
}

<!-- Vista -->
<DataGrid ItemsSource="{Binding Info}" />

You must have the Datagrid as accessible property from the view, in the tutorial it is well explained.

I hope it serves you.

    
answered by 30.06.2017 в 17:22