DomainUpDown.Sorted 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定值,指出是否排序項目集合。
public:
property bool Sorted { bool get(); void set(bool value); };
public bool Sorted { get; set; }
member this.Sorted : bool with get, set
Public Property Sorted As Boolean
屬性值
如果項目集合已排序,則為 true
,否則為 false
。 預設值是 false
。
範例
下列程式碼範例會建立並初始化 DomainUpDown 控制項。 此範例可讓您設定部分屬性,並建立字串集合,以顯示在微調方塊中 (也稱為上下按鈕控制項) 。 程式碼假設 TextBox CheckBox 、 和 Button 已在表單上具現化。 此範例也假設您在類別層級宣告為名為 myCounter
的 32 位帶正負號整數的成員變數。 您可以在文字方塊中輸入字串,並在按一下按鈕時將其新增至 Items 集合。 按一下核取方塊,您可以切換 屬性, Sorted 並觀察微調方塊中專案集合的差異。
protected:
DomainUpDown^ domainUpDown1;
private:
void MySub()
{
// Create and initialize the DomainUpDown control.
domainUpDown1 = gcnew System::Windows::Forms::DomainUpDown;
// Add the DomainUpDown control to the form.
Controls->Add( domainUpDown1 );
}
void button1_Click( System::Object^ sender,
System::EventArgs^ e )
{
// Add the text box contents and initial location in the collection
// to the DomainUpDown control.
domainUpDown1->Items->Add( String::Concat(
(textBox1->Text->Trim()), " - ", myCounter.ToString() ) );
// Increment the counter variable.
myCounter = myCounter + 1;
// Clear the TextBox.
textBox1->Text = "";
}
void checkBox1_Click( Object^ sender, EventArgs^ e )
{
// If Sorted is set to true, set it to false;
// otherwise set it to true.
if ( domainUpDown1->Sorted )
{
domainUpDown1->Sorted = false;
}
else
{
domainUpDown1->Sorted = true;
}
}
void domainUpDown1_SelectedItemChanged( Object^ sender, EventArgs^ e )
{
// Display the SelectedIndex and SelectedItem property values in a MessageBox.
MessageBox::Show( String::Concat( "SelectedIndex: ",
domainUpDown1->SelectedIndex.ToString(), "\n", "SelectedItem: ",
domainUpDown1->SelectedItem->ToString() ) );
}
protected DomainUpDown domainUpDown1;
private void MySub()
{
// Create and initialize the DomainUpDown control.
domainUpDown1 = new System.Windows.Forms.DomainUpDown();
// Add the DomainUpDown control to the form.
Controls.Add(domainUpDown1);
}
private void button1_Click(System.Object sender,
System.EventArgs e)
{
// Add the text box contents and initial location in the collection
// to the DomainUpDown control.
domainUpDown1.Items.Add((textBox1.Text.Trim()) + " - " + myCounter);
// Increment the counter variable.
myCounter = myCounter + 1;
// Clear the TextBox.
textBox1.Text = "";
}
private void checkBox1_Click(System.Object sender,
System.EventArgs e)
{
// If Sorted is set to true, set it to false;
// otherwise set it to true.
if (domainUpDown1.Sorted)
{
domainUpDown1.Sorted = false;
}
else
{
domainUpDown1.Sorted = true;
}
}
private void domainUpDown1_SelectedItemChanged(System.Object sender,
System.EventArgs e)
{
// Display the SelectedIndex and SelectedItem property values in a MessageBox.
MessageBox.Show("SelectedIndex: " + domainUpDown1.SelectedIndex.ToString()
+ "\n" + "SelectedItem: " + domainUpDown1.SelectedItem.ToString());
}
Protected domainUpDown1 As DomainUpDown
Private Sub MySub()
' Create and initialize the DomainUpDown control.
domainUpDown1 = New System.Windows.Forms.DomainUpDown()
' Add the DomainUpDown control to the form.
Controls.Add(domainUpDown1)
End Sub
Private Sub button1_Click(sender As System.Object, e As System.EventArgs)
' Add the text box contents and initial location in the collection
' to the DomainUpDown control.
domainUpDown1.Items.Add((textBox1.Text.Trim() & " - " & myCounter))
' Increment the counter variable.
myCounter = myCounter + 1
' Clear the TextBox.
textBox1.Text = ""
End Sub
Private Sub checkBox1_Click(sender As System.Object, e As System.EventArgs)
' If Sorted is set to true, set it to false;
' otherwise set it to true.
If domainUpDown1.Sorted Then
domainUpDown1.Sorted = False
Else
domainUpDown1.Sorted = True
End If
End Sub
Private Sub domainUpDown1_SelectedItemChanged _
(sender As System.Object, e As System.EventArgs)
' Display the SelectedIndex and SelectedItem property values in a MessageBox.
MessageBox.Show(("SelectedIndex: " & domainUpDown1.SelectedIndex.ToString() & _
ControlChars.Cr & "SelectedItem: " & domainUpDown1.SelectedItem.ToString()))
End Sub
備註
當 設定為 true
時 Sorted ,集合會依字母順序排序。