惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
F
Fortinet All Blogs
Engineering at Meta
Engineering at Meta
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
The Exploit Database - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
Intezer
P
Privacy & Cybersecurity Law Blog
M
MIT News - Artificial intelligence
MyScale Blog
MyScale Blog
P
Privacy International News Feed
MongoDB | Blog
MongoDB | Blog
Project Zero
Project Zero
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tenable Blog
Security Latest
Security Latest
Stack Overflow Blog
Stack Overflow Blog
L
Lohrmann on Cybersecurity
V
Vulnerabilities – Threatpost
Microsoft Azure Blog
Microsoft Azure Blog
NISL@THU
NISL@THU
T
Threat Research - Cisco Blogs
L
LangChain Blog
Simon Willison's Weblog
Simon Willison's Weblog
WordPress大学
WordPress大学
SecWiki News
SecWiki News
博客园 - 三生石上(FineUI控件)
Forbes - Security
Forbes - Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
GRAHAM CLULEY
K
Kaspersky official blog
W
WeLiveSecurity
A
Arctic Wolf
TaoSecurity Blog
TaoSecurity Blog
Recorded Future
Recorded Future
AI
AI
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Last Week in AI
Last Week in AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
雷峰网
雷峰网
GbyAI
GbyAI
S
SegmentFault 最新的问题
N
News and Events Feed by Topic
C
CXSECURITY Database RSS Feed - CXSecurity.com
Google Online Security Blog
Google Online Security Blog
博客园 - Franky
罗磊的独立博客

博客园 - 牵牛望岳

ICloneable 接口--c# 深复制与浅复制 IDisposable接口详解 C# 中用 PadLeft、PadRight 补足位数 IsPostBack用法,Page.IsValid的用法 IIf函数 替换、恢复Html中的特殊字符 C#连接数据库的一些鲜为人知的方法 C#关键字 【推荐】常用 SQL 语句大全 CSS中的黄金分割率 几条相关SQL语句 解析.net中ref和out的实质 JavaScript substr() 和 substring() 方法的区别 武林外传搞笑语录 调试和跟踪 VS2005单元测试[转] 几个.Net开源的CMS、Portal系统 DataKeyNames工作 查询后,翻页问题的解决办法2。(GridView1.PageIndex = e.NewPageIndex;) (转)
listbox控件的一些操作
牵牛望岳 · 2009-04-16 · via 博客园 - 牵牛望岳

1. 属性列表:

    SelectionMode    组件中条目的选择类型,即多选(Multiple)、单选(Single)
    Rows            
列表框中显示总共多少行
    Selected        
检测条目是否被选中
    SelectedItem    
返回的类型是ListItem,获得列表框中被选择的条目
    Count           
列表框中条目的总数
    SelectedIndex   
列表框中被选择项的索引值
    Items           
泛指列表框中的所有项,每一项的类型都是ListItem

2. 取列表框中被选中的值  

     ListBox.SelectedValue  

3. 动态的添加列表框中的项:

     ListBox.Items.Add("所要添加的项");

4. 移出指定项:

     //首先判断列表框中的项是否大于0
     If(ListBox.Items.Count > 0 )
     {
//
移出选择的项
ListBox.Items.Remove(ListBox.SelectedItem);
     }

5. 清空所有项:

     //首先判断列表框中的项是否大于0
     If(ListBox.Items.Count > 0 )
     {
//
清空所有项
ListBox.Items.Clear();
     }

6. 列表框可以一次选择多项:
   
    
只需设置列表框的属性 SelectionMode="Multiple",Ctrl可以多选

7. 两个列表框联动,即两级联动菜单

     //判断第一个列表框中被选中的值
     switch(ListBox1.SelectValue)
     {
//
如果是"A",第二个列表框中就添加这些:
case "A"
      ListBox2.Items.Clear();
      ListBox2.Items.Add("A1");
      ListBox2.Items.Add("A2");
      ListBox2.Items.Add("A3");
//
如果是"B",第二个列表框中就添加这些:
case "B"
      ListBox2.Items.Clear();
      ListBox2.Items.Add("B1");
      ListBox2.Items.Add("B2");
      ListBox2.Items.Add("B3");
     }

8. 实现列表框中项的移位
    
即:向上移位、向下移位
    
具体的思路为:创建一个ListBox对象,并把要移位的项先暂放在这个对象中。
    
如果是向上移位,就是把当前选定项的的上一项的值赋给当前选定的项,然后
    
把刚才新加入的对象的值,再附给当前选定项的前一项。
    
具体代码为:
      //
定义一个变量,作移位用
      index = -1;
      //
将当前条目的文本以及值都保存到一个临时变量里面
      ListItem lt=new ListItem (ListBox.SelectedItem.Text,ListBox.SelectedValue);
      //
被选中的项的值等于上一条或下一条的值
      ListBox.Items[ListBox.SelectedIndex].Text=ListBox.Items[ListBox.SelectedIndex + index].Text;
      //
被选中的项的值等于上一条或下一条的值
      ListBox.Items[ListBox.SelectedIndex].Value=ListBox.Items[ListBox.SelectedIndex + index].Value;
      //
把被选中项的前一条或下一条的值用临时变量中的取代
      ListBox.Items[ListBox.SelectedIndex].Test=lt.Test;
      //
把被选中项的前一条或下一条的值用临时变量中的取代
      ListBox.Items[ListBox.SelectedIndex].Value=lt.Value;
      //
把鼠标指针放到移动后的那项上
      ListBox.Items[ListBox.SelectedIndex].Value=lt.Value;

9. 移动指针到指定位置:

      (1).移至首条
          //
将被选中项的索引设置为0OK
          ListBox.SelectIndex=0;
      (2).
移至尾条
          //
将被选中项的索引设置为ListBox.Items.Count-1OK
          ListBox.SelectIndex=ListBox.Items.Count-1;
      (3).
上一条
          //
用当前被选中的索引去减 1
          ListBox.SelectIndex=ListBox.SelectIndex - 1;
      (4).
下一条
          //
用当前被选中的索引去加 1
          ListBox.SelectIndex=ListBox.SelectIndex + 1;

this.ListBox1.Items.Insertat(3,new   ListItem("插入在第3行之后项",""));  

this.ListBox1.Items.Insertat(index,ListItem)

ListBox1.Items.Insert(0,new   ListItem("text","value"));