lundi 15 août 2016

sorting list of checkbox wpf

I have a WPF application with Grid That contains 3 columns with a checkbox in last one and textbox in other columns and create dynamic rows when i try to sort the list then refill the grid the check box didn't sort was and keep as it before sorting this is my sorting code

       public void btn_name_Click(object sender, RoutedEventArgs e)
    {
        lc = lc.OrderBy(x => x.productName).ToList();
       // List<ListClass> newList = lc.OrderBy(x => x.productName).ToList();
        ReFill();
    } 

and the refiilig code

         public void ReFill()
    {
        try
        {
            int rowT = 0,RowC = 0;
            int ColNum = 0;
            TextBox NewT = new TextBox();
            List<string> Pnames = lc.Select(x => x.productName).ToList();
            foreach (UIElement element in grid1.Children)
            {
                if ((element.GetType() == NewT.GetType()) )
                {

                    NewT = (TextBox)element;
                    if (ColNum == 0) 
                    {
                        NewT.Text = lc[rowT].productName;
                        ColNum = 1;
                    }
                    else if (ColNum == 1)
                    {
                        NewT.Text = lc[rowT].Quantity.ToString();
                        ColNum = 0;
                        rowT++;
                    }


                }
                else if (element.GetType() == CB.GetType())
                {
                    CB = (CheckBox)element;
                    // CB.IsChecked = lc[RowC].ischecked;
                    int rowIndex = Grid.GetRow(element);
                    lc[rowIndex].ischecked = (bool)CB.IsChecked;
                    RowC++;
                    ColNum = 0;
                }
            }
        }
        catch { }
    }

Aucun commentaire:

Enregistrer un commentaire