如题:
奇怪有高手帮忙解释 在listbox 里设置 多行字符串 其中有两行字符串 只有大小写区分 当我将小写的一行移到大写那行时小写变成了大写 当我将大写的一行移到小写那行时大写变成了小写 但是当我将不同字符串移动过他们 他们又恢复正确的大小写 这是为什么呢
一下是上移下移代码
private void button1_Click(object sender, EventArgs e)
{
if (listBoxOut.SelectedItem != null)
{
if (listBoxOut.SelectedIndex > 0)
{
int index = listBoxOut.SelectedIndex;
string selectNamePre = listBoxOut.Items [index-1].ToString ();
string selectName = listBoxOut.Items[index ].ToString();
// listBoxOut.Items[index - 1] = "";
// listBoxOut.Items[index] = "";
listBoxOut.Items[index - 1] = selectName;
listBoxOut.Items[index] = selectNamePre;
listBoxOut.SelectedIndex--; } }
} private void buttonDown_Click(object sender, EventArgs e)
{
if (listBoxOut.SelectedItem != null)
{
int nowCount = listBoxOut.Items .Count ;
if (listBoxOut.SelectedIndex < nowCount-1)
{
int index = listBoxOut.SelectedIndex;
string selectNamePre = listBoxOut.Items[index + 1].ToString();
string selectName = listBoxOut.Items[index].ToString();
// listBoxOut.Items[index+ 1] = "";
// listBoxOut.Items[index] = "";
listBoxOut.Items[index +1] = selectName;
listBoxOut.Items[index] = selectNamePre;
listBoxOut.SelectedIndex++; } }
}
我试过先赋空值再 调换值 是正常显示的
奇怪有高手帮忙解释 在listbox 里设置 多行字符串 其中有两行字符串 只有大小写区分 当我将小写的一行移到大写那行时小写变成了大写 当我将大写的一行移到小写那行时大写变成了小写 但是当我将不同字符串移动过他们 他们又恢复正确的大小写 这是为什么呢
一下是上移下移代码
private void button1_Click(object sender, EventArgs e)
{
if (listBoxOut.SelectedItem != null)
{
if (listBoxOut.SelectedIndex > 0)
{
int index = listBoxOut.SelectedIndex;
string selectNamePre = listBoxOut.Items [index-1].ToString ();
string selectName = listBoxOut.Items[index ].ToString();
// listBoxOut.Items[index - 1] = "";
// listBoxOut.Items[index] = "";
listBoxOut.Items[index - 1] = selectName;
listBoxOut.Items[index] = selectNamePre;
listBoxOut.SelectedIndex--; } }
} private void buttonDown_Click(object sender, EventArgs e)
{
if (listBoxOut.SelectedItem != null)
{
int nowCount = listBoxOut.Items .Count ;
if (listBoxOut.SelectedIndex < nowCount-1)
{
int index = listBoxOut.SelectedIndex;
string selectNamePre = listBoxOut.Items[index + 1].ToString();
string selectName = listBoxOut.Items[index].ToString();
// listBoxOut.Items[index+ 1] = "";
// listBoxOut.Items[index] = "";
listBoxOut.Items[index +1] = selectName;
listBoxOut.Items[index] = selectNamePre;
listBoxOut.SelectedIndex++; } }
}
我试过先赋空值再 调换值 是正常显示的
你试试直接把两行对调位置,不用这个赋值的方法行不行。