我正在使用 WPF 和 C# 开发一个项目。在一个窗口上,我有大约 7 个列表框,其中包含相同数量的项目。这些项目实际上是相互关联的。它类似于网格。
lisBox1 | lisBox2 | lisBox3 | lisBox4 | lisBox5 | lisBox6 | lisBox7
每当第三个列表框的 SelectedIndex 改变时,所有其他列表框的 SelectedIndex 都设置为等于第三个列表框的 SelectedIndex。这允许用户突出显示用户实际正在阅读的行。
当我将项目部署在运行 Windows XP 的客户机器上时,索引没有得到很好的管理!每个列表框的索引都会定期更改,我无法从所有列表框中获取所选项目的索引,即每个列表框可能/可能没有不同的索引。
我还注意到,在客户端的机器上,列表框能够选择多个项目,我在运行 VS10 和 Windows 8 的开发机器上禁用并正常工作。
它与Windows XP有关吗?
请建议我这些问题的原因是什么?任何解决的想法将不胜感激。提前致谢。
标记
<ListBox Height="auto" HorizontalAlignment="Left" Margin="30,201,0,0" Name="listBox1" VerticalAlignment="Top" Width="40" FontStyle="Italic" SelectionChanged="listBox1_SelectionChanged" />
<ListBox Height="auto" HorizontalAlignment="Left" Margin="75,201,0,0" Name="listBox2" VerticalAlignment="Top" Width="85" FontStyle="Italic" SelectionChanged="listBox2_SelectionChanged" />
<ListBox Height="auto" HorizontalAlignment="Left" Margin="163,201,0,0" Name="listBox3" VerticalAlignment="Top" Width="190" FontWeight="Bold" FontStyle="Italic" SelectionChanged="listBox3_SelectionChanged" KeyDown="listBox3_KeyDown" />
<ListBox Height="auto" HorizontalAlignment="Left" Margin="355,201,0,0" Name="listBox4" VerticalAlignment="Top" Width="90" FontStyle="Italic" SelectionChanged="listBox4_SelectionChanged" />
<ListBox Height="auto" HorizontalAlignment="Left" Margin="449,201,0,0" Name="listBox5" VerticalAlignment="Top" Width="55" FontStyle="Italic" SelectionChanged="listBox5_SelectionChanged" />
<ListBox Height="auto" HorizontalContentAlignment="Right" HorizontalAlignment="Left" Margin="505,201,0,0" Name="listBox6" VerticalAlignment="Top" Width="80" FontWeight="Bold" SelectionChanged="listBox6_SelectionChanged" />
<ListBox Height="auto" HorizontalContentAlignment="Right" HorizontalAlignment="Left" Margin="590,201,0,0" Name="listBox7" VerticalAlignment="Top" Width="80" FontWeight="Bold" SelectionChanged="listBox7_SelectionChanged" />
<ListBox Height="auto" HorizontalContentAlignment="Right" HorizontalAlignment="Left" Margin="675,201,0,0" Name="listBox8" VerticalAlignment="Top" Width="95" FontWeight="Bold" SelectionChanged="listBox8_SelectionChanged" />
代码:
private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
listBox2.SelectedIndex = listBox1.SelectedIndex;
}
private void listBox2_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
listBox3.SelectedIndex = listBox2.SelectedIndex;
}
private void listBox3_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
listBox4.SelectedIndex = listBox3.SelectedIndex;
}
private void listBox4_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
listBox5.SelectedIndex = listBox4.SelectedIndex;
}
private void listBox5_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
listBox6.SelectedIndex = listBox5.SelectedIndex;
}
private void listBox6_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
listBox7.SelectedIndex = listBox6.SelectedIndex;
}
private void listBox7_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
listBox8.SelectedIndex = listBox7.SelectedIndex;
}
private void listBox8_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
listBox1.SelectedIndex = listBox8.SelectedIndex;
}
我的电脑就是这样,完美!
这就是它在 XP 上的样子。
这就是我的电脑上的多选关闭并且工作正常的方式。
这就是多选打开的方式,并且在 Windows XP 上总是选择 listbox3 中的第一项。