现在的位置: 首页 > 综合 > 正文

贴两段代码

2011年03月28日 ⁄ 综合 ⁄ 共 1544字 ⁄ 字号 评论关闭

因为没有找到如何在ComboBox和ListBox中的item附加tag的办法,所以自己添加了一下。主要是试验一下如何用博客园新加的代码高亮这个酷酷的功能:

public class FlexComboBox : System.Windows.Forms.ComboBox
    
{
        
private System.Collections.ArrayList ItemValues = new System.Collections.ArrayList();
        
public void FlexAddItem(string itemText, object itemValue)
        
{
            
this.Items.Add(itemText);
            ItemValues.Add(itemValue);
        }

        
public object FlexGetSelectedItemValue()
        
{
            
return ItemValues[this.SelectedIndex];
        }

        
public void FlexClearItems()
        
{
            ItemValues.Clear();
            
this.Items.Clear();
        }

    }

public class FlexListBox : System.Windows.Forms.ListBox
    
{
        
private ArrayList itemValues = new ArrayList();
        
public FlexListBox() { }

        
public void FlexAddItem(string itemText, object itemValue)
        
{
            
this.Items.Add(itemText);
            itemValues.Add(itemValue);
        }

        
public void FlexRemoveSelectedItems()
        
{
            
for(int i=0;i<this.SelectedIndices.Count;i++)
            
{
                
int index = this.SelectedIndices[i];
                
this.Items.RemoveAt(index);
                itemValues.RemoveAt(index);
            }

        }

        
public void FlexClearItems()
        
{
            itemValues.Clear();
            
this.Items.Clear();
        }

        
public ArrayList FlexGetItemValues()
        
{
            
return itemValues;
        }

        
public object FlexGetSelectedValue()
        
{
            
return itemValues[this.SelectedIndex];
        }

    }

抱歉!评论已关闭.