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 。 该示例允许你设置一些属性,并创建字符串集合,以便在旋转框中显示, (也称为向上控件) 。 代码假定窗体上已实例化,TextBoxCheckBox并且Button已实例化。 该示例还假定在类级别声明为 32 位有符号整数 myCounter
的成员变量。 可以在文本框中输入字符串,并在单击按钮时将其添加到 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,集合按字母顺序排序。