Home > Net >  C # propertygrid custom attributes checklistbox valuechanged how to obtain checklistbox state?
C # propertygrid custom attributes checklistbox valuechanged how to obtain checklistbox state?

Time:12-16

# region propertygrid set start
Public static ArrayList ArrayList=new ArrayList ();//input field


Public class CheckedListBoxUC: CheckedListBox
{
Private System. Windows. Forms. Design. IWindowsFormsEditorService m_iws;

Private string m_selectStr=string. The Empty;

///& lt; Summary>
///get chosen field, multiple fields separated by "|"
///& lt;/summary>
Public string SelectedFields
{
The get
{
Return this. M_selectStr;
}

}

Public void SetCheck (object value)
{
Try
{
String s=value. The ToString ();
String [] result=s.S plit (' | ');

This. The Items. The Clear ();
for (int i=0; I & lt; Arraylist. Count; I++)
{
Enclosing the Items. The Add (arraylist [I]);
}

for (int i=0; I & lt; Result. The Length; I++)
{
For (int k=0; K & lt; Arraylist. Count; K++)
{
If (result [I]==arraylist [k]. ToString ())
{
//SetItemCheckState (k, CheckState. Checked).
Enclosing SetItemChecked (k, true);
}
}
}
}

The catch (Exception ex)
{
//MessageBox. Show (ex. The Message, "Error", MessageBoxButtons. OK, MessageBoxIcon. Error);
}
}

//value="https://bbs.csdn.net/topics/X | Y";
Public CheckedListBoxUC (System. Windows. Forms. Design. IWindowsFormsEditorService iws)
{
Enclosing m_iws=iws;
Enclosing the Visible=true;
This. Height=100;
Enclosing BorderStyle=BorderStyle. None;
//add event
This. Leave +=new EventHandler (checkedListBoxUC_Leave);
Enclosing SelectedIndexChanged +=new System. EventHandler (enclosing checklist_SelectedIndexChanged);
Try
{
/*
String [] strsFields=LayerParams. The GetFields ();
Enclosing BeginUpdate ();
This. The Items. The Clear ();
if (null !=strsFields)
{
for (int i=0; I & lt; StrsFields. Length; I++)
{
Enclosing the Items. The Add (strsFields [I]);
}
}
*/
}
The catch (Exception ex)
{
MessageBox. Show (ex. The Message, "Error", MessageBoxButtons. OK, MessageBoxIcon. Error);
}
The finally
{
Enclosing EndUpdate ();
}
}

Private void checklist_SelectedIndexChanged (object sender, EventArgs e)
{
//m_selectStr=this. SelectedItem. ToString ();
}

Void checkedListBoxUC_Leave (object sender, EventArgs e)
{
List LstStrs=new List (a);
for (int i=0; I & lt; Enclosing the Items. The Count; I++)
{
If (this. GetItemChecked (I))
{
LstStrs. Add ((string) enclosing the Items [I] the ToString ());
}

}
M_selectStr=string. Join (" | ", lstStrs ToArray ());
This. M_iws. CloseDropDown ();
}
}//checklistbox

Public class ListBoxUCConverter: System. Drawing. Design. UITypeEditor
{
Public override UITypeEditorEditStyle GetEditStyle (ITypeDescriptorContext context)
{
Return System. Drawing. Design. UITypeEditorEditStyle. The DropDown can;
}

Public override the object EditValue (ITypeDescriptorContext context, IServiceProvider provider, object value)
{
System. Windows. Forms. Design. IWindowsFormsEditorService iws=(. System. Windows Forms. Design. IWindowsFormsEditorService) provider. GetService (typeof (System. Windows. Forms. Design. IWindowsFormsEditorService));
If (iws!=null)
{
CheckedListBoxUC chkListBoxUC=new CheckedListBoxUC (iws);
//chkListBoxUC. The DataSource=arraylist;
ChkListBoxUC. SetCheck (value);
Iws. DropDownControl (chkListBoxUC);

Return chkListBoxUC. SelectedFields;
}
return value;
}
}//convertor


How to get behind checklistbox state, and how to invoke checklistbox? Is also began to which a few items for the selected, how to set up the selected how to judge state change after the change?
  •  Tags:  
  • C#
  • Related