掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
.NET2003で複数列表示のコンボボックスにするには? (ID:79244)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
> .NET2003のコンボボックス これは、System.Web.UI.WebControls.DropDownList の事ではなく、 System.Windows.Forms.ComboBox クラスの事ですよね? とりあえず、こんな感じにしてみては如何でしょう。 コードにもう少し手を加えれば、汎用的な複数列対応ComboBoxコントロールにもできるかも。 Private Class ItemData Public ISBN As String Public Title As String Public Sub New(ByVal ISBN As String, ByVal Title As String) Me.ISBN = ISBN Me.Title = Title End Sub Public Overrides Function ToString() As String Return Title End Function End Class Private mySize As SizeF Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With Me.ComboBox1 .DrawMode = DrawMode.OwnerDrawFixed .DropDownStyle = ComboBoxStyle.DropDown mySize = .CreateGraphics.MeasureString("0-00000-000-0", .Font) .Items.Add(New ItemData("4-7981-0216-4", "標準 VB.NETプログラミング")) .Items.Add(New ItemData("1-56592-670-6", "Visual Basic Shell Programming")) .Items.Add(New ItemData("4-88135-831-6", "COM IDL & インターフェイスデザイン")) End With End Sub Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem Const Margin As Integer = 5% Dim Item As ItemData = DirectCast(Me.ComboBox1.Items(e.Index), ItemData) Dim myPen As New Pen(Color.Brown) Dim SeparatorPosition As Single Dim B As Brush If e.State = DrawItemState.Selected Then B = SystemBrushes.HighlightText Else B = SystemBrushes.WindowText End If e.DrawBackground() With e.Graphics SeparatorPosition = Margin * 2 + mySize.Width .DrawString(Item.ISBN, e.Font, B, Margin, e.Bounds.Y) .DrawString(Item.Title, e.Font, B, SeparatorPosition + Margin, e.Bounds.Y) .DrawLine(myPen, SeparatorPosition, e.Bounds.Top, SeparatorPosition, e.Bounds.Bottom) End With End Sub
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2020 Takeshi Okamoto All Rights Reserved.