CheckedListBox.ObjectCollection.Add Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Lägger till ett objekt i listan med objekt för en CheckedListBox.
Överlagringar
| Name | Description |
|---|---|
| Add(Object, Boolean) |
Lägger till ett objekt i listan med objekt för en CheckedListBox, som anger objektet som ska läggas till och om det är markerat. |
| Add(Object, CheckState) |
Lägger till ett objekt i listan med objekt för en CheckedListBox, som anger det objekt som ska läggas till och det första markerade värdet. |
Add(Object, Boolean)
Lägger till ett objekt i listan med objekt för en CheckedListBox, som anger objektet som ska läggas till och om det är markerat.
public:
int Add(System::Object ^ item, bool isChecked);
public int Add(object item, bool isChecked);
override this.Add : obj * bool -> int
Public Function Add (item As Object, isChecked As Boolean) As Integer
Parametrar
- item
- Object
Ett objekt som representerar objektet som ska läggas till i samlingen.
- isChecked
- Boolean
trueför att kontrollera objektet; annars . false
Returer
Indexet för det nyligen tillagda objektet.
Exempel
Följande kodexempel visar hur du initierar en CheckedListBox kontroll genom att ange CheckOnClickegenskaperna , SelectionModeoch ThreeDCheckBoxes . Exemplet fyller i CheckedListBox med kontroller och anger DisplayMember egenskapen till Control.Name kontrollens egenskap.
Om du vill köra exemplet klistrar du in följande kod i ett formulär som innehåller namnet CheckedListBox CheckedListBox1 och anropar InitializeCheckListBox metoden från formulärets konstruktor eller Load metod.
// This method initializes CheckedListBox1 with a list of all
// the controls on the form. It sets the selection mode
// to single selection and allows selection with a single click.
// It adds itself to the list before adding itself to the form.
internal:
System::Windows::Forms::CheckedListBox^ CheckedListBox1;
private:
void InitializeCheckedListBox()
{
this->CheckedListBox1 = gcnew CheckedListBox;
this->CheckedListBox1->Location = System::Drawing::Point( 40, 90 );
this->CheckedListBox1->CheckOnClick = true;
this->CheckedListBox1->Name = "CheckedListBox1";
this->CheckedListBox1->Size = System::Drawing::Size( 120, 94 );
this->CheckedListBox1->TabIndex = 1;
this->CheckedListBox1->SelectionMode = SelectionMode::One;
this->CheckedListBox1->ThreeDCheckBoxes = true;
System::Collections::IEnumerator^ myEnum = this->Controls->GetEnumerator();
while ( myEnum->MoveNext() )
{
Control^ aControl = safe_cast<Control^>(myEnum->Current);
this->CheckedListBox1->Items->Add( aControl, false );
}
this->CheckedListBox1->DisplayMember = "Name";
this->CheckedListBox1->Items->Add( CheckedListBox1 );
this->Controls->Add( this->CheckedListBox1 );
}
// This method initializes CheckedListBox1 with a list of all
// the controls on the form. It sets the selection mode
// to single selection and allows selection with a single click.
// It adds itself to the list before adding itself to the form.
internal System.Windows.Forms.CheckedListBox CheckedListBox1;
private void InitializeCheckedListBox()
{
this.CheckedListBox1 = new CheckedListBox();
this.CheckedListBox1.Location = new System.Drawing.Point(40, 90);
this.CheckedListBox1.CheckOnClick = true;
this.CheckedListBox1.Name = "CheckedListBox1";
this.CheckedListBox1.Size = new System.Drawing.Size(120, 94);
this.CheckedListBox1.TabIndex = 1;
this.CheckedListBox1.SelectionMode = SelectionMode.One;
this.CheckedListBox1.ThreeDCheckBoxes = true;
foreach ( Control aControl in this.Controls )
{
this.CheckedListBox1.Items.Add(aControl, false);
}
this.CheckedListBox1.DisplayMember = "Name";
this.CheckedListBox1.Items.Add(CheckedListBox1);
this.Controls.Add(this.CheckedListBox1);
}
' This method initializes CheckedListBox1 with a list of all the controls
' on the form. It sets the selection mode to single selection and
' allows selection with a single click. It adds itself to the list before
' adding itself to the form.
Friend WithEvents CheckedListBox1 As System.Windows.Forms.CheckedListBox
Private Sub InitializeCheckedListBox()
Me.CheckedListBox1 = New CheckedListBox
Me.CheckedListBox1.Location = New System.Drawing.Point(40, 90)
Me.CheckedListBox1.CheckOnClick = True
Me.CheckedListBox1.Name = "CheckedListBox1"
Me.CheckedListBox1.Size = New System.Drawing.Size(120, 94)
Me.CheckedListBox1.TabIndex = 1
Me.CheckedListBox1.SelectionMode = SelectionMode.One
Me.CheckedListBox1.ThreeDCheckBoxes = True
Dim aControl As Control
For Each aControl In Me.Controls
Me.CheckedListBox1.Items.Add(aControl, False)
Next
Me.CheckedListBox1.DisplayMember = "Name"
Me.CheckedListBox1.Items.Add(CheckedListBox1)
Me.Controls.Add(Me.CheckedListBox1)
End Sub
Kommentarer
Den här metoden lägger till ett objekt i listan. För en lista läggs objektet till i slutet av den befintliga listan med objekt. För en sorterad markerad listruta infogas objektet i listan enligt dess sorterade position. En SystemException inträffar om det inte finns tillräckligt med utrymme för att lagra det nya objektet.
Gäller för
Add(Object, CheckState)
Lägger till ett objekt i listan med objekt för en CheckedListBox, som anger det objekt som ska läggas till och det första markerade värdet.
public:
int Add(System::Object ^ item, System::Windows::Forms::CheckState check);
public int Add(object item, System.Windows.Forms.CheckState check);
override this.Add : obj * System.Windows.Forms.CheckState -> int
Public Function Add (item As Object, check As CheckState) As Integer
Parametrar
- item
- Object
Ett objekt som representerar objektet som ska läggas till i samlingen.
- check
- CheckState
Den första CheckState för den kontrollerade delen av objektet.
Returer
Indexet för det nyligen tillagda objektet.
Undantag
Parametern check är inte ett av de giltiga CheckState värdena.
Kommentarer
Den här metoden lägger till ett objekt i den markerade listrutan. För en osorterad markerad listruta läggs objektet till i slutet av den befintliga listan med objekt. För en sorterad markerad listruta infogas objektet i listan enligt dess sorterade position. En SystemException inträffar om det inte finns tillräckligt med utrymme för att lagra det nya objektet.