列表框中的更新时间在两侧显示相同的数据。 [英] On update time in listbox show same data in both side.

查看:44
本文介绍了列表框中的更新时间在两侧显示相同的数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用ListBox。当我获取更新数据时,listbox1和listbox2中会显示相同的数据。但是我尝试从listbox2中删除数据,这些数据已经在Listbox2中被删除了



我尝试过:



I use ListBox in my project. When I get data for update then same data show in listbox1 and listbox2. But I try to remove data from listbox1 which is alread in Listbox2

What I have tried:

if (updateById == null) return;
btnSave.CommandArgument = updateById.CityDetailsId.ToString(CultureInfo.InvariantCulture);
BindStateDetails();
ddlState.SelectedValue = Convert.ToString(updateById.StateId);
BindCityList();
//libAdminCity.DataSource = updateById.CityName;
message3 = updateById.VCityId;
message4 = updateById.CityName;
string[] arr = message4.Split(',');

for (int i = 0; i < arr.Length; i++)
{
    foreach (ListItem item in libAdminCity.Items)
    {
       // int j = 0;
       // if (item.Text == arr[i])
        if (libVendorCity.Items.Contains(item))
        {

            //libVendorCity.Items.Add(new ListItem(Convert.ToString(item.Text), Convert.ToString(item.Value)));
            libAdminCity.Items.Remove(item);

        }
        //else
        //{
        //    libVendorCity.Items.Add(new ListItem(Convert.ToString(item.Text), Convert.ToString(item.Value)));
        //}

    }


}

推荐答案

你的问题似乎是你的Contains()永远不会返回true,因为它并不是你想要的。具有相同文本的两个项目仍然是关于此方法的两个不同项目。



您需要遍历libVendorCity ListBox并比较每个项目Text属性和if它匹配你执行Remove()。
Your problem seems to be that your Contains() never returns true as it does not exactly what you want. Two items that have the same Text are still two distinct items with regards to this method.

You need to loop over the libVendorCity ListBox and compare each item Text property and if it matches you do the Remove().


这篇关于列表框中的更新时间在两侧显示相同的数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆