自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

經(jīng)典C# ListBox操作實(shí)況

開發(fā) 后端
下面的代碼就是C# ListBox操作實(shí)況的展示,很有意義,希望能給大家?guī)韼椭?/div>

C#  ListBox操作實(shí)況

  1. protectedvoidButton1_Click(objectsender,EventArgse)   
  2. {   
  3. ListItemnewItem=newListItem();   
  4. newItem.Text=this.TextBox3.Text;   
  5. newItem.Value=this.TextBox4.Text;   
  6. this.ListBox1.Items.Add(newItem);   
  7. }   
  8. //得到設(shè)置最大數(shù)量   
  9. //原Capacity的容量為8,默認(rèn)的情況下會(huì)隨著新增項(xiàng)(ListItem)的數(shù)量增多會(huì)成2倍的增長81632..   
  10. //但如果設(shè)置了Capacity的大小,就不會(huì)自動(dòng)增長了   
  11. protectedvoidButton2_Click(objectsender,EventArgse)   
  12. {   
  13. Response.Write("原大小:"+this.ListBox1.Items.Capacity.ToString());   
  14. this.ListBox1.Items.Capacity=6;   
  15. Response.Write("更改后:"+this.ListBox1.Items.Capacity.ToString());}//清空items集合中所有的項(xiàng)   
  16. protectedvoidButton3_Click(objectsender,EventArgse)   
  17. {   
  18. this.ListBox1.Items.Clear();   
  19. }//判斷集合中是否包含指定項(xiàng)   
  20. protectedvoidButton4_Click(objectsender,EventArgse)   
  21. {   
  22. ListItemitem=newListItem(this.TextBox1.Text,this.TextBox2.Text);   
  23. if(this.ListBox1.Items.Contains(item))   
  24. {   
  25. Response.Write("yes");;   
  26. }   
  27. else   
  28. {   
  29. Response.Write("no");   
  30. }}//將items中的所有項(xiàng)復(fù)制到listItemCollection集合中   
  31. protectedvoidButton5_Click(objectsender,EventArgse)   
  32. {   
  33. ListItem[]items=newListItem[this.ListBox1.Items.Count];   
  34. this.ListBox1.Items.CopyTo(items,0);   
  35. ListBoxlistBox2=newListBox();   
  36. listBox2.ID="ListBox2";   
  37. listBox2.Items.AddRange(items);   
  38. //得到ListBox1的位置,并將listBox2放到ListBox1后面   
  39. intposition=0;   
  40. foreach(Controlcinthis.form1.Controls)   
  41. {   
  42. position++;   
  43. if(c.ID=="ListBox1")   
  44. {   
  45. break;   
  46. }   
  47. }   
  48. this.form1.Controls.AddAt(position,listBox2);}//得到集合中項(xiàng)的數(shù)量protectedvoidButton6_Click(objectsender,EventArgse)   
  49. {   
  50. Response.Write(this.ListBox1.Items.Count.ToString());   
  51. }   
  52. //根據(jù)文本查找,如果找到則返回此項(xiàng),如果找不到則返加null   
  53. protectedvoidButton7_Click(objectsender,EventArgse)   
  54. {   
  55. ListItemitem=this.ListBox1.Items.FindByText(this.TextBox1.Text);   
  56. if(item!=null)   
  57. {   
  58. Response.Write(item.Text+":"+item.Value);   
  59. }   
  60. }   
  61. //根據(jù)值查找,如果找到則返回此項(xiàng),如果找不到則返加null   
  62. protectedvoidButton8_Click(objectsender,EventArgse)   
  63. {   
  64. ListItemitem=this.ListBox1.Items.FindByText(this.TextBox2.Text);   
  65. if(item!=null)   
  66. {   
  67. Response.Write(item.Text+":"+item.Value);   
  68. }   
  69. }   
  70. //所查找項(xiàng)的索引   
  71. protectedvoidButton9_Click(objectsender,EventArgse)   
  72. {   
  73. ListItemitem=this.ListBox1.Items.FindByText(this.TextBox1.Text);   
  74. if(item!=null)   
  75. {   
  76. intposition=this.ListBox1.Items.IndexOf(item);   
  77. Response.Write("所查找項(xiàng)的索引:"+position.ToString());   
  78. }   
  79. }//插入新建項(xiàng)   
  80. protectedvoidButton10_Click(objectsender,EventArgse)   
  81. {   
  82. ListItemnewItem=newListItem(this.TextBox1.Text,this.TextBox2.Text);   
  83. this.ListBox1.Items.Insert(0,newItem);   
  84. }//刪除節(jié)點(diǎn)   
  85. protectedvoidButton11_Click(objectsender,EventArgse)   
  86. {   
  87. ListItemitem=newListItem(this.TextBox1.Text,this.TextBox2.Text);   
  88. this.ListBox1.Items.Remove(item);   
  89. }//根據(jù)索引位置刪除   
  90. protectedvoidButton12_Click(objectsender,EventArgse)   
  91. {   
  92. intindex=this.ListBox1.Items.IndexOf(newListItem(this.TextBox1.Text,this.TextBox2.Text));   
  93. this.ListBox1.Items.RemoveAt(index);   
  94. }//選中項(xiàng)   
  95. protectedvoidButton13_Click(objectsender,EventArgse)   
  96. {   
  97. this.TextBox1.Text=this.ListBox1.SelectedItem.Text;   
  98. this.TextBox2.Text=this.ListBox1.SelectedItem.Value;   
  99. }//修改   
  100. protectedvoidButton14_Click(objectsender,EventArgse)   
  101. {   
  102. this.ListBox1.SelectedItem.Text=this.TextBox3.Text;   
  103. this.ListBox1.SelectedItem.Value=this.TextBox4.Text;   
  104. }   
  105.   

以上介紹了C#  ListBox的操作方法,可謂是C#  ListBox操作實(shí)況,希望能給大家?guī)韼椭?/P>

【編輯推薦】

  1. 解析C# Socket編程實(shí)現(xiàn)訪問網(wǎng)絡(luò)的原理
  2. C# switch語句簡單描述
  3. C# ServiceController類剖析
  4. C#抓取網(wǎng)頁程序的實(shí)現(xiàn)淺析
  5. C#內(nèi)存管理詳細(xì)分析
責(zé)任編輯:阡陌 來源: 網(wǎng)絡(luò)轉(zhuǎn)載
相關(guān)推薦

2009-09-08 17:37:54

C# listbox控

2009-09-08 16:10:03

C# ListBox

2009-08-12 15:50:40

C# ListBox

2009-08-19 11:21:02

C# ListBox控

2009-08-14 14:19:50

Enhanced LiC#構(gòu)建

2009-09-08 16:34:49

C# Listbox

2009-09-08 15:12:07

C# ListBox

2009-09-10 12:00:09

C# listbox

2009-09-08 14:54:40

C# listBox控

2009-09-08 16:22:27

c# listBox

2009-09-08 16:01:58

C# ListBox

2009-09-11 09:15:32

C# get set

2009-09-08 15:50:44

c# listbox

2009-09-08 14:21:38

CheckBox翻頁選

2011-07-04 15:14:49

C#

2009-08-17 13:34:02

C#異步操作

2009-08-12 15:43:02

操作C# Datase

2009-09-08 14:43:41

C# listbox

2009-08-19 10:42:08

C#操作Word表格

2009-09-07 06:07:46

C#窗體設(shè)計(jì)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)