item listbox (UWP)

1

With this code I add items to listbosx with the amount of registration I have. How to have a check before to know if the item of that record has already been added and does not act item with the same none of id?

 private void button_Click(object sender, RoutedEventArgs e)
    {
        using (_connection = new teste; Data Source=192.168.0.17;User Id=RFID;Password=1234;SslMode=None;"))
        {
            System.Text.EncodingProvider ppp;
            ppp = System.Text.CodePagesEncodingProvider.Instance;
            Encoding.RegisterProvider(ppp);

            _connection.Open();
            var cmd = new MySqlCommand("SELECT distinct id FROM test", _connection);

            using (var reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {

                    listBox.Items.Add(("Registro: " +reader.GetString("id")));


                }
            }
        }
    
asked by anonymous 14.03.2017 / 12:19

1 answer

1
while (reader.Read())
{


int index = listbox.Items.IndexOf(reader.GetString("id"));
if(index< 0)
{
    listBox.Items.Add(("Registro: " +reader.GetString("id")));
}

}

If it does not find the index it means that it does not exist then just add it in the list, see if it helps ^^

    
14.03.2017 / 12:30