mercredi 1 mars 2017

ListView Item checkbox getting duplicated

It a weird issue , atleast for me. I am going nuts.

I am adding checkboxes to a LISTVIEW using simple arrayList.

My code basically does this. Reads configuration details from a config file, and based on the file entry creates checkboxes in there different LISTview.

@ listvies are working fine with my approach, but not able to understand why for one of them the checkbox is getting duplicated.

I checked the count of ArrayList being added to list box, its 1. I che number of checkboxes created by my code, its even 1

But UI have 2 checkboxes, Please help.

    <ListView Margin="122,15,226,0"  Background="{x:Null}" Name="app_list_view" Grid.Row="1" Grid.ColumnSpan="6" ItemsSource="{Binding}"  />

    <ListView Height="96" HorizontalAlignment="Left" Margin="126,14,0,0" Name="silo_list_view" VerticalAlignment="Top" Width="87" Background="{x:Null}" Grid.Row="1" Grid.Column="5" Grid.RowSpan="2" ItemsSource="{Binding}"/>

    <ListView Height="95" HorizontalAlignment="Left" Margin="17,15,0,0" VirtualizingStackPanel.IsVirtualizing="False" Name="reg_list_view" VerticalAlignment="Top" Width="103" Background="{x:Null}" Grid.Row="1" Grid.Column="5" Grid.RowSpan="2" ItemsSource="{Binding}"/>

Hear Goes My code:

 private void create_dynamic_checkboxes()
    {
    //Checkboxes List from APP,env and Silo
    ArrayList app_list_chkb = new  ArrayList();
    ArrayList env_list_chkb = new  ArrayList();
    ArrayList silo_list_chkb = new ArrayList();

    //Read Confgi File
       List<string> cfg_data =System.IO.File.ReadAllText(@"Config_file_path").Split('\n').ToList();

    //Filter Server wise
    cfg_data = cfg_data.Where(serv => serv.Split('|')[0].Equals(this.current_server)).ToList();


    List<string> app_list_from_cfg = new List<string>();
    List<string> env_list_from_cfg = new List<string>();
    List<string> silo_list_from_cfg = new List<string>();

    //Get App list from config
    foreach(var cfg in cfg_data)
        app_list_from_cfg.Add(cfg.Split('|')[1]);

    //app_list_from_cfg = app_list_from_cfg.Distinct().ToList();
    app_list_from_cfg = app_list_from_cfg.GroupBy(x=>x).Select(x=>x.First()).ToList();

    //Get Env list from config
    foreach (var cfg in cfg_data)
        env_list_from_cfg.Add(cfg.Split('|')[4]);

  //  env_list_from_cfg = env_list_from_cfg.Distinct().ToList();
    env_list_from_cfg = env_list_from_cfg.GroupBy(x => x).Select(x => x.First()).ToList();

    Console.WriteLine("env_list_chkb COUNT===>" + env_list_from_cfg.Count);


    //Get Silo list from config
    foreach (var cfg in cfg_data)
        silo_list_from_cfg.Add(cfg.Split('|')[3]);

    //silo_list_from_cfg = silo_list_from_cfg.Distinct().ToList();
    silo_list_from_cfg = silo_list_from_cfg.GroupBy(x => x).Select(x => x.First()).ToList();


    //Creating checkboxes with EventHandler

    foreach (var app in app_list_from_cfg)
    {
        CheckBox ckb = new CheckBox();
        ckb.Content = app;
        ckb.Click += new RoutedEventHandler(addRemoveAppFromList);

        app_list_chkb.Add(ckb);

    }
    foreach (var app in env_list_from_cfg)
    {
        CheckBox ckb = new CheckBox();
        ckb.Content = app;
        ckb.Click += new RoutedEventHandler(addRemoveRegFromList);

        env_list_chkb.Add(ckb);

        Console.WriteLine("ENV ADDED");

    }
    foreach (var app in env_list_from_cfg)
    {
        CheckBox ckb = new CheckBox();
        ckb.Content = app;
        ckb.Click += new RoutedEventHandler(addRemoveRegFromList);

        env_list_chkb.Add(ckb);

    }
    foreach (var app in silo_list_from_cfg)
    {
        CheckBox ckb = new CheckBox();
        ckb.Content = app;
        ckb.Click += new RoutedEventHandler(addRemoveSiloFromList);

        silo_list_chkb.Add(ckb);

    }


    app_list_view.ItemsSource = app_list_chkb;
    reg_list_view.ItemsSource = env_list_chkb;
    silo_list_view.ItemsSource = silo_list_chkb;

}

My Config File looks like this:

TFABRDU2|APSIA|apsiadev|silo4|int|apsiadev_silo4_int|eful_mq_wrt_qltb_silo4_int.pset
TFABRDU2|APSIA|apsiadev|silo4|int|apsiadev_silo4_int|logger.pset
TFABRDU2|APSIA|apsiadev|silo4|int|apsiadev_silo4_int|mq_auditor.pset
TFABRDU2|APSIA|apsiadev|silo4|int|apsiadev_silo4_int|mq_service_dcs_q21_silo4_int.pset
TFABRDU2|APSIA|apsiadev|silo4|int|apsiadev_silo4_int|mq_service_prt_q21_silo4_int.pset



TFABRDU2|APSSIA|dapsia01|silo1|int|dapsia01_silo1_int|sia_auditor.pset
TFABRDU2|APSSIA|dapsia01|silo1|int|dapsia01_silo1_int|sia_logger.pset
TFABRDU2|APSSIA|dapsia01|silo1|int|dapsia01_silo1_int|sia_mq_auditor.pset

CheckBoxes for INT is getting duplicated and showing 2 checkboxes.

Aucun commentaire:

Enregistrer un commentaire