2011-08-24 3 views
2

VS2010 콤보 상자 (CB) 구성 요소에 대해 묻고 싶습니다 ... CB (Multilevel) (CB)와 비슷한 것을 만들 수 있습니까? CB의 항목을 범주로 나눌 수 있습니까?더 많은 레이어가있는 Visual Studio (2010) 콤보 상자

HTML (태그 OPTGROUP)와 유사한 구성 요소가있다 - 내가 필요한 것을 정확히 : 답변

multilevel combobox in html

고맙습니다 매우

PS를 : 내 영어에 대한 미안 해요, 난 희망 내가 정확히 설명했습니다

+0

어떤 UI 기술이 필요합니까? Windows Forms, WebForms, WPF, Silverlight? – Jehof

+0

죄송합니다 .. WinForms에서 필요합니다. – flipis

답변

2

ComboBoxDrawModeOwnerDrawFixed으로 변경하면 다음을 사용할 수 있습니다. 헤더와 항목을 그리는 DrawItem 이벤트. 그러나 사용자가 헤더 항목을 선택하지 못하도록 할 수있는 방법은 없습니다.

private List<string> groupItems = new List<string>(); 

private void Form1_Load(object sender, EventArgs e) 
{ 
    groupItems.Add("Great Bands"); 
    groupItems.Add("Great Bandages"); 

    comboBox1.DrawMode = DrawMode.OwnerDrawFixed; 
    comboBox1.Items.Add("Great Bands"); 
    comboBox1.Items.Add("Led Zeppelin"); 
    comboBox1.Items.Add("Steppenwolf"); 
    comboBox1.Items.Add("Great Bandages"); 
    comboBox1.Items.Add("Band-Aid"); 
    comboBox1.Items.Add("Curad"); 
} 

private void comboBox1_DrawItem(object sender, DrawItemEventArgs e) 
{ 
    e.DrawBackground(); 

    if (e.Index > -1) 
    { 
    string drawText = comboBox1.Items[e.Index].ToString(); 
    if (groupItems.Contains(drawText)) 
    { 
     using (Font font = new Font(comboBox1.Font, FontStyle.Bold)) 
     e.Graphics.DrawString(drawText, font, Brushes.Black, e.Bounds); 
    } 
    else 
     e.Graphics.DrawString(drawText, comboBox1.Font, Brushes.Black, new Rectangle(16, e.Bounds.Top, e.Bounds.Width - 16, e.Bounds.Height)); 

    e.DrawFocusRectangle(); 
    } 
}