listBox1里面有几个项,我选中其中一项,当我单击列表框的空白地方时,如何不选中任何项?
private void listBox1_Click(object sender,EventArgs e)
{}还有 点击空白的地方时,ListBoxs.SelectedIndex等于多少?

解决方案 »

  1.   

    ListBoxs.SetSelect(ListBoxs.Items.Count-1,false);给分啊 private void listBox_FenLei_MouseDown(object sender, MouseEventArgs e)
            {
                    if (this.listBox_FenLei.SelectedItem != null)
                    {
                        //此句可防止双击空白处出现错误的问题                     indexofsource = ((ListBox)sender).IndexFromPoint(e.X, e.Y);
                      
                         if (indexofsource == ListBox.NoMatches)    //如果点的是空白
                          {
                              if (this.listBox_FenLei.Items.Count != 0)
                            {
                                this.listBox_FenLei.SetSelected(this.listBox_FenLei.Items.Count - 1, false);
                            }                    }
                                        
                    }