listbox item (UWP)

Asked

Viewed 56 times

1

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

 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")));


                }
            }
        }

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 means that it does not exist then just add to the list, see if it helps ^^

Browser other questions tagged

You are not signed in. Login or sign up in order to post.