none
¿como hago para obtener y modificar datos de un grid, sin data table ni data gridview, porque estos no son accesibles en UWP? RRS feed

  • Pregunta

  • tengo un boton que añade datos a un grid, el problema es al querer eliminar un dato correspondiente al codigo indicado no puedo comparar el codigo con los elementos en el grid ni obtener el index de dicho elemento, trate de agregar x:name a cada elemento pero no se puede desde linea de codigo solo en el xaml.

    este es el codigo que agrega los datos:

    private async void añadir_Click(object sender, RoutedEventArgs e)
            {
                TextBlock formato = new TextBlock();
                Thickness margin = formato.Margin;
                margin.Right = 10;
                if (cod.Text == "" || cant.Text == "")
                {
                    var dialog = new MessageDialog("No puden haber datos vacios");
                    await dialog.ShowAsync();
                }
                else
                {
                    if (fac.RowDefinitions.Count > 0)
                    {
                        RowDefinition rowDef1 = new RowDefinition();
                        fac.RowDefinitions.Add(rowDef1);
                        TextBlock txt6 = new TextBlock();
                        txt6.Text = cod.Text; txt6.Margin = margin;
                        Grid.SetRow(txt6, cont1 + 1);
                        Grid.SetColumn(txt6, 0);
                        TextBlock txt7 = new TextBlock();
                        MySqlDataReader dr;
                        dr = conexcion.leersql("SELECT nombre FROM produc where cod ='" + cod.Text + "';");
                        dr.Read();
                        costo.Items.Add(dr.GetString(0));
                        txt7.Text = dr.GetString(0); txt7.Margin = margin;
                        Grid.SetRow(txt7, cont1 + 1);
                        Grid.SetColumn(txt7, 1);
                        TextBlock txt8 = new TextBlock();
                        txt8.Text = cant.Text; txt8.Margin = margin;
                        Grid.SetRow(txt8, cont1 + 1);
                        Grid.SetColumn(txt8, 2);
                        TextBlock txt9 = new TextBlock();
                        txt9.Text = costo.SelectedItem.ToString(); txt9.Margin = margin;
                        Grid.SetRow(txt9, cont1 + 1);
                        Grid.SetColumn(txt9, 3);
                        TextBlock txt10 = new TextBlock();
                        double st = Convert.ToDouble(txt8.Text) * Convert.ToDouble(txt9.Text);
                        txt10.Text = st.ToString(); txt10.Margin = margin;
                        Grid.SetRow(txt10, cont1 + 1);
                        Grid.SetColumn(txt10, 4);
                        fac.Children.Add(txt6);
                        fac.Children.Add(txt7);
                        fac.Children.Add(txt8);
                        fac.Children.Add(txt9);
                        fac.Children.Add(txt10);
                    }
                    else
                    {
                        ColumnDefinition colDef1 = new ColumnDefinition();
                        ColumnDefinition colDef2 = new ColumnDefinition();
                        ColumnDefinition colDef3 = new ColumnDefinition();
                        ColumnDefinition colDef4 = new ColumnDefinition();
                        ColumnDefinition colDef5 = new ColumnDefinition();
                        fac.ColumnDefinitions.Add(colDef1);
                        fac.ColumnDefinitions.Add(colDef2);
                        fac.ColumnDefinitions.Add(colDef3);
                        fac.ColumnDefinitions.Add(colDef4);
                        fac.ColumnDefinitions.Add(colDef5);
                        RowDefinition rowDef1 = new RowDefinition();
                        fac.RowDefinitions.Add(rowDef1);
                        RowDefinition rowDef2 = new RowDefinition();
                        fac.RowDefinitions.Add(rowDef2);
                        TextBlock txt1 = new TextBlock();
                        txt1.Text = "Codigo"; txt1.FontSize = 20; txt1.FontWeight = FontWeights.Bold; txt1.Margin = margin;
                        Grid.SetRow(txt1, 0);
                        Grid.SetColumn(txt1, 0);
                        TextBlock txt2 = new TextBlock();
                        txt2.Text = "Descripción"; txt2.FontSize = 20; txt2.FontWeight = FontWeights.Bold; txt2.Margin = margin;
                        Grid.SetRow(txt2, 0);
                        Grid.SetColumn(txt2, 1);
                        TextBlock txt3 = new TextBlock();
                        txt3.Text = "Cantidad"; txt3.FontSize = 20; txt3.FontWeight = FontWeights.Bold; txt3.Margin = margin;
                        Grid.SetRow(txt3, 0);
                        Grid.SetColumn(txt3, 2);
                        TextBlock txt4 = new TextBlock();
                        txt4.Text = "Precio"; txt4.FontSize = 20; txt4.FontWeight = FontWeights.Bold; txt4.Margin = margin;
                        Grid.SetRow(txt4, 0);
                        Grid.SetColumn(txt4, 3);
                        TextBlock txt5 = new TextBlock();
                        txt5.Text = "Sub Total"; txt5.FontSize = 20; txt5.FontWeight = FontWeights.Bold; txt5.Margin = margin;
                        Grid.SetRow(txt5, 0);
                        Grid.SetColumn(txt5, 4);
                        TextBlock txt6 = new TextBlock();
                        txt6.Text = cod.Text; txt6.Margin = margin;
                        Grid.SetRow(txt6, 1);
                        Grid.SetColumn(txt6, 0);
                        TextBlock txt7 = new TextBlock();
                        MySqlDataReader dr;
                        dr = conexcion.leersql("SELECT nombre FROM produc where cod ='" + cod.Text + "';");
                        dr.Read();
                        costo.Items.Add(dr.GetString(0));
                        txt7.Text = dr.GetString(0); txt7.Margin = margin;
                        Grid.SetRow(txt7, 1);
                        Grid.SetColumn(txt7, 1);
                        TextBlock txt8 = new TextBlock();
                        txt8.Text = cant.Text; txt8.Margin = margin;
                        Grid.SetRow(txt8, 1);
                        Grid.SetColumn(txt8, 2);
                        TextBlock txt9 = new TextBlock();
                        txt9.Text = costo.SelectedItem.ToString(); txt9.Margin = margin;
                        Grid.SetRow(txt9, 1);
                        Grid.SetColumn(txt9, 3);
                        TextBlock txt10 = new TextBlock();
                        double st = Convert.ToDouble(txt8.Text) * Convert.ToDouble(txt9.Text);
                        txt10.Text = st.ToString(); txt5.Margin = margin;
                        Grid.SetRow(txt10, 1);
                        Grid.SetColumn(txt10, 4);
                        fac.Children.Add(txt1);
                        fac.Children.Add(txt2);
                        fac.Children.Add(txt3);
                        fac.Children.Add(txt4);
                        fac.Children.Add(txt5);
                        fac.Children.Add(txt6);
                        fac.Children.Add(txt7);
                        fac.Children.Add(txt8);
                        fac.Children.Add(txt9);
                        fac.Children.Add(txt10);
                    }
                }
                cod.Text = "";
                cant.Text = "";
                costo.Items.Clear();
            }

    • Cambiado Joyce_AC martes, 30 de mayo de 2017 13:57
    lunes, 15 de mayo de 2017 13:29