黑马程序员技术交流社区

标题: ComboBox的四个关于Selected的属性区别? [打印本页]

作者: 刘景发    时间: 2011-11-20 21:42
标题: ComboBox的四个关于Selected的属性区别?
本帖最后由 刘景发 于 2011-11-21 13:05 编辑

我了解其中两个属性的用法,即ComboBox.SelectedIndex是关于索引的;ComboBox.SelectedItem是关于哪项被选中的;但对于其它两个ComboBox.SelectedValue和ComboBox.SelectedText的作用和区别是什么?:(
作者: 乔克    时间: 2011-11-21 10:32

SelectedIndex
SelectedItem
SelectedText
  1.             this.comboBox1.Items.AddRange(new object[] {
  2.             "男",
  3.             "女",
  4.             "未知"});
复制代码
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;

  9. namespace WindowsFormsApplication1
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         public Form1()
  14.         {
  15.             InitializeComponent();

  16.         }

  17.         private void Form1_Load(object sender, EventArgs e)
  18.         {
  19.             comboBox1.SelectedItem = "未知";
  20.          
  21.            
  22.         }


  23.         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  24.         {
  25.             try
  26.             {
  27.                 textBox1.Text += "SelectedItem:" + comboBox1.SelectedItem + "  类型:" + comboBox1.SelectedItem.GetType() + "\r\n";
  28.                 textBox1.Text += "SelectedIndex:" + comboBox1.SelectedIndex.ToString() + "  类型:" + comboBox1.SelectedIndex.GetType() + "\r\n";
  29.                 textBox1.Text += "SelectedText:" + comboBox1.SelectedText + "  类型:" + comboBox1.SelectedText.GetType() + "\r\n";
  30.             }
  31.             catch (Exception ex)
  32.             {
  33.                 throw (ex);
  34.             }
  35.         }
  36.     }
  37. }
复制代码
SelectedValue  看这个
http://blog.csdn.net/downmoon/article/details/6159191
作者: 刘景发    时间: 2011-11-21 11:37
谢谢您这么热情的回复,我已经懂了,自己查过一些资料……{:soso_e100:}
作者: 杨楠    时间: 2011-11-21 17:31
selectedvalue是下拉框项的值,selectedtext是下拉框该项所显示的内容




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2