Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 插入时列表框项目消失/不显示_C#_Winforms_Visual Studio 2008_Telerik - Fatal编程技术网

C# 插入时列表框项目消失/不显示

C# 插入时列表框项目消失/不显示,c#,winforms,visual-studio-2008,telerik,C#,Winforms,Visual Studio 2008,Telerik,我正在两个列表框之间创建一个数据传输控件。 我在两个框中都显示了项目,文本和属性值保存数据。 但是,当我从一个传输到另一个时,我可以访问传输的项(使用debug)并查看text属性(而不是value属性),但它不会显示在发送到的列表框中。 我甚至尝试过刷新对象,但没有成功 谁能告诉我我做错了什么 private void btnToLeft_Click(object sender, EventArgs e) { Telerik.WinControls.UI.Rad

我正在两个列表框之间创建一个数据传输控件。 我在两个框中都显示了项目,文本和属性值保存数据。 但是,当我从一个传输到另一个时,我可以访问传输的项(使用debug)并查看text属性(而不是value属性),但它不会显示在发送到的列表框中。 我甚至尝试过刷新对象,但没有成功

谁能告诉我我做错了什么

private void btnToLeft_Click(object sender, EventArgs e)
    {
            Telerik.WinControls.UI.RadListDataItem item = new Telerik.WinControls.UI.RadListDataItem(lstRight.SelectedItem.DisplayValue.ToString(), lstRight.SelectedItem.Value);
            lstLeft.Items.Add(item);
            lstRight.Items.RemoveAt(lstRight.SelectedItem.RowIndex);
            lstLeft.Refresh();
            lstRight.Refresh();
    }

这是我在类似情况下使用的代码

private void btnToLeft_Click(object sender, EventArgs e)
{
      if (lstRight.Items.Count == 0) { return; }
      if (lstRight.SelectedItem == null) { return; }

      RadListDataItem item = lstRight.SelectedItem;
      lstRight.Items.Remove(item);
      lstLeft.Items.Add(item);
}
你可以让它更通用一些

private void MoveToTargetListBox(RadListControl sourceListBox, RadListControl targetListBox)
{
  try
  {
    if (sourceListBox.Items.Count == 0) { return; }
    if (sourceListBox.SelectedItem == null) { return; }

    RadListDataItem item = sourceListBox.SelectedItem;
    sourceListBox.Items.Remove(item);
    targetListBox.Items.Add(item);
  }
  catch (Exception ex)
  {
    //handle Exception
  }
}

private void btnToLeft_Click(object sender, EventArgs e)
{
  MoveToTargetListBox(lstRight, lstLeft);
}

private void btnToRight_Click(object sender, EventArgs e)
{
  MoveToTargetListBox(lstLeft, lstRight);
}

这是我在类似情况下使用的代码

private void btnToLeft_Click(object sender, EventArgs e)
{
      if (lstRight.Items.Count == 0) { return; }
      if (lstRight.SelectedItem == null) { return; }

      RadListDataItem item = lstRight.SelectedItem;
      lstRight.Items.Remove(item);
      lstLeft.Items.Add(item);
}
你可以让它更通用一些

private void MoveToTargetListBox(RadListControl sourceListBox, RadListControl targetListBox)
{
  try
  {
    if (sourceListBox.Items.Count == 0) { return; }
    if (sourceListBox.SelectedItem == null) { return; }

    RadListDataItem item = sourceListBox.SelectedItem;
    sourceListBox.Items.Remove(item);
    targetListBox.Items.Add(item);
  }
  catch (Exception ex)
  {
    //handle Exception
  }
}

private void btnToLeft_Click(object sender, EventArgs e)
{
  MoveToTargetListBox(lstRight, lstLeft);
}

private void btnToRight_Click(object sender, EventArgs e)
{
  MoveToTargetListBox(lstLeft, lstRight);
}

我想我知道了。我引用了lstRight.SelectedItem.DisplayValue.ToString()而不是文本值-lstRight.SelectedItem.text


现在好像工作了

我想我知道了。我引用了lstRight.SelectedItem.DisplayValue.ToString()而不是文本值-lstRight.SelectedItem.text


现在好像工作了

谢谢,这对我来说几乎是可行的-当我移动物品时,它的价值就丢失了。你知道我怎样才能让它保持不变吗?谢谢,这对我来说几乎是可行的-当我把物品移过去时,它的价值就消失了。你知道我怎样才能让它保持下去吗?