The Artima Developer Community
Sponsored Link

.NET Buzz Forum
ComboBox als DropDownList kann kein Text gesetzt werden

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
-

Posts: 1524
Nickname: nitronic
Registered: Jul, 2006

Norbert Eder works as a software architect.
ComboBox als DropDownList kann kein Text gesetzt werden Posted: Dec 28, 2006 2:04 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by -.
Original Post: ComboBox als DropDownList kann kein Text gesetzt werden
Feed Title: Norbert Eder - Living .NET
Feed URL: http://feeds.feedburner.com/NorbertEder-Livingnet
Feed Description: Copyright (c)2005, 2006 by Norbert Eder
Latest .NET Buzz Posts
Latest .NET Buzz Posts by -
Latest Posts From Norbert Eder - Living .NET

Advertisement
Wer eine ComboBox verwendet und die Eigenschaft DropDownStyle auf DropDownList gesetzt hat, kann keinen Text mehr setzen. Dadurch entf��llt auch die M��glichkeit, einen Default-Text zu setzen, wenn kein Item ausgew��hlt ist/wurde. Dem kann durch eine kurze und schnell Ableitung leicht Abhilfe geschafft werden.

public partial class ComboBoxEx : ComboBox
{
private Label _statusLabel = new Label();
private string _statusText = null;

public string StatusText
{
get { return this._statusText; }
set { this._statusText = value; }
}

public ComboBoxEx()
{
InitializeComponent();

Init();

this.Controls.Add(this._statusLabel);

this._statusLabel.Click += new EventHandler(_statusLabel_Click);
this.SizeChanged += new EventHandler(ComboBoxEx_SizeChanged);
this.SelectedIndexChanged += new EventHandler(ComboBoxEx_SelectedIndexChanged);
}

void _statusLabel_Click(object sender, EventArgs e)
{
this.DroppedDown = true;
}

void ComboBoxEx_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.SelectedItem == null)
Init();
else
this._statusLabel.Visible = false;
}

void ComboBoxEx_SizeChanged(object sender, EventArgs e)
{
Init();
}

public void Init()
{
if (this.DropDownStyle == ComboBoxStyle.DropDownList)
{
this._statusLabel.Visible = true;
this._statusLabel.Location = new Point(1, 1);
this._statusLabel.Size = new Size(this.Width - 20, this.Height - 2 );

if (this._statusText != null)
{
this._statusLabel.Text = this._statusText;
this._statusLabel.Font = this.Font;
}
else
{
this._statusLabel.Text = "[Nothing selected]";
}
this._statusLabel.BringToFront();
}
else
{
this._statusLabel.Visible = false;
}
}
}

Es wird direkt von der ComboBox abgeleitet. Die neue Klasse erh��lt die Eigenschaft StatusText mit dessen Hilfe ein entsprechender Text gesetzt werden kann, der angezeigt wird, wenn kein Item ausgew��hlt ist.

Read: ComboBox als DropDownList kann kein Text gesetzt werden

Topic: Extreme ASP.NET: Client-Side Web Service Calls with AJAX Extensions Previous Topic   Next Topic Topic: CLR Inside Out: Introduction to COM Interop

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use