samedi 28 juillet 2018

Button for checkbox worked once

I have created checkboxes. When user check any item the item display in datagridview.
This is the code of checkbox in xmal

<Grid Background="#FFE5E5E5">

                                    <ListBox HorizontalAlignment="Stretch"  Name="APIList" 
                      VerticalAlignment="Stretch" ItemsSource="{Binding Tables[0]}"  
                      ItemTemplate="{StaticResource NameColumnTemplate}" 
                      ScrollViewer.VerticalScrollBarVisibility="Auto" 
                     BorderBrush="#FFAD7F30"  
             SelectionChanged="lst_SelectionChanged" CheckBox.Click="lst_SelectionChanged"/>
                                    <Button Content="listbox" Height="23" HorizontalAlignment="Left" Margin="214,207,0,0" Name="btnShowSelectedItems" 
            VerticalAlignment="Top" Width="75" Click="btnShowSelectedItems_Click" />


                            </Grid>

This is the code behind

 private void btnShowSelectedItems_Click(object sender, RoutedEventArgs e)
    {
        string path, name;
        int i = 0,c=0, result;
        string[] lines = System.IO.File.ReadAllLines(@"D:\7th semester\FYP\source\repos\dllPaths.txt");
        string[] selecteditem = new string[50];
        var showapi = APIList.ItemsSource as List<showAPI>;
        var apinames = new List<showAPI>();
        foreach (var item in showapi)
        {
            if (item.IsSelected == true)
            {
                selecteditem[i] = item.apiName;
            }
        }
        foreach (string line in lines)
        {
            foreach (string select in selecteditem)
            {
                if (select == line)
                {
                    name = select + ".exe";
                    path = lines[i + 1];
                    result = injection(name, path);
                    if (result == 1)
                    {
                        apinames.Add(new showAPI
                        {
                            ID = 1,
                            apiName = select,
                            dateTime = DateTime.Now.ToString()
                        });
                    }
                    else { Textbox1.Text = c.ToString(); }
                }
            }
        }


        dg1.ItemsSource = apinames;
    }
    private void lst_SelectionChanged(object sender, RoutedEventArgs e)
    {
        var listBox = sender as ListBox;
        if (listBox.SelectedIndex > -1)
        {

            Console.WriteLine(APIList.SelectedIndex);
            Console.WriteLine(((CheckBox)APIList.SelectedItem).IsChecked);
        }
    }

When user click on button checked items display in table but if user again check more items and again click on button nothing happen and result remain unchanged. In short this button work only once.
If anyone know solution kindly help




Aucun commentaire:

Enregistrer un commentaire