2008-09-13 10 views

उत्तर

6

एलन एंडरसन आप ऐसा करते हैं यह बताने के लिए एक कस्टम नियंत्रण बनाया दृश्य स्टूडियो का उपयोग कर रहा हूँ। आप इसे यहाँ पा सकते हैं: http://www.codeproject.com/KB/list/aa_listview.aspx

यहाँ कि नियंत्रण के लिए कुछ उदाहरण कोड है:


    GlacialList mylist = new GlacialList(); 

mylist.Columns.Add("Column1", 100); // this can also be added 

     // through the design time support 

mylist.Columns.Add("Column2", 100); 
mylist.Columns.Add("Column3", 100); 
mylist.Columns.Add("Column4", 100); 

GLItem item; 

item = this.glacialList1.Items.Add("Atlanta Braves"); 
item.SubItems[1].Text = "8v"; 
item.SubItems[2].Text = "Live"; 
item.SubItems[2].BackColor = Color.Bisque; 
item.SubItems[3].Text = "MLB.TV"; 

item = this.glacialList1.Items.Add("Florida Marlins"); 
item.SubItems[1].Text = ""; 
item.SubItems[2].Text = "Delayed"; 
item.SubItems[2].BackColor = Color.LightCoral; 
item.SubItems[3].Text = "Audio"; 


item.SubItems[1].BackColor = Color.Aqua; // set the background 

     // of this particular subitem ONLY 

item.UserObject = myownuserobjecttype; // set a private user object 

item.Selected = true; // set this item to selected state 

item.SubItems[1].Span = 2; // set this sub item to span 2 spaces 


ArrayList selectedItems = mylist.SelectedItems; 
      // get list of selected items 
1

इसके बजाय आप एक ग्रिड व्यू का उपयोग कर सकते हैं, क्योंकि इससे आपको कॉलम सामग्री का अधिक अच्छा नियंत्रण मिल जाता है।

+0

क्या आपके पास इसका कोई उदाहरण है? – leora

+0

हाँ, कुछ ऐसा है: myGridDataView.Columns.Add (नया DataGridViewCheckBoxColumn()); – Keith

0

आप TreeViewAdv आज़मा सकते हैं। यह ओपन सोर्स है और Sourceforge पर होस्ट किया गया है।

17

बेहतर उपयोग ग्रिड दृश्य नियंत्रण, लेकिन अगर आप चेक बॉक्स के साथ ही एक स्तंभ चाहते हैं और उस स्तंभ पहले एक है तुम सिर्फ लिख सकते हैं:

this.listView1.CheckBoxes = true; 
+0

उपरोक्त, हालांकि मुझे लगता है कि यह पहला कॉलम नहीं होना चाहिए; –

4

नीचे की तरह चेकबॉक्स कॉलम जोड़ें।

myListView.CheckBoxes = true; 
myListView.Columns.Add(text, width, alignment); 

नीचे की तरह जोड़े ListViewItem रों।

ListViewItem lstViewItem = new ListViewItem(); 
lstViewItem.SubItems.Add("Testing.."); 
lstViewItem.SubItems.Add("Testing1.."); 

myListView.Items.Add(lstViewItem); 
1

आप true को CheckBoxes संपत्ति सेट कर सकते हैं की कोशिश क्यों नहीं करते। कोड में यह इस तरह किया जा सकता है:

listView1.CheckBoxes = true;