! 제품 버전을 정확하게 입력해 주세요.
제품 버전이 정확하게 기재되어 있지 않은 경우,
최신 버전을 기준으로 안내 드리므로
더욱 빠르고 명확한 안내를 위해
제품 버전을 정확하게 입력해 주세요!

다중선택이 가능한 콤보박스 > Q&A | 토론

본문 바로가기

Spread.NET

Q&A | 토론

WinForms윈폼 다중선택이 가능한 콤보박스

페이지 정보

작성자 cc22 작성일 2021-09-13 15:04 조회 2,765회 댓글 0건
제품 버전 : .NET spread 13
컨트롤 이름 : ComboBox, CheckBox, CheckComboBox

본문



첨부의 사진처럼 다중선택이 가능한 콤보박스를 만들어보고 싶은데

스프레드 디자이너의 속성에서 찾을수가 없는 듯 합니다


알려주시면 감사하겠습니다



 

  • 페이스북으로 공유
  • 트위터로  공유
  • 링크 복사
  • 카카오톡으로 보내기

댓글목록

등록된 댓글이 없습니다.

1 답변

WinForms윈폼 Re: 다중선택이 가능한 콤보박스

추천0 이 글을 추천하셨습니다 비추천0 채택채택

페이지 정보

작성자 GCK루카스 작성일 2021-09-14 16:40 댓글 0건

본문

안녕하세요 그레이프시티입니다.


해당 기능이 기본적으로 제공되진 않지만 아래 코드를 사용하여 구현이 가능합니다.

CustomComboBoxCellType cellType = new CustomComboBoxCellType();
string[] labels = new string[10];
for (int i = 0; i < labels.Length; i++)
{
    labels[i] = i.ToString();
}
cellType.Items = labels; fpSpread1.ActiveSheet.Cells["B2"].CellType = cellType;
fpSpread1.ActiveSheet.Columns[1].Width = 200;
public class CustomComboBoxCellType : EditBaseCellType
{
    public CustomComboBoxCellType()
    {
        ButtonAlign = ButtonAlign.Right;
        DropDownButton = true;
        SubEditor = new CheckedListBoxSubEditor();
    }

    public override Control GetEditorControl(FarPoint.Win.Spread.Appearance appearance, float zoomFactor)
    {
        GeneralEditor customEditor = new GeneralEditor();
        InitializeEditorControl(customEditor, appearance, zoomFactor);
        return customEditor;
    }

    public override void InitializeEditorControl(Control control, FarPoint.Win.Spread.Appearance appearance, float zoomFactor)
    {
        base.InitializeEditorControl(control, appearance, zoomFactor);

        GeneralEditor customEditor = (GeneralEditor)control;


        CheckedListBoxSubEditor checkedListBox = (CheckedListBoxSubEditor)customEditor.SubEditor;
        checkedListBox.Items.Clear();
        checkedListBox.Items.AddRange(Items);
    }

    public override object GetEditorValue()
    {
        if (SubEditor is CheckedListBoxSubEditor editor)
        {
            CheckedListBox.CheckedItemCollection checkedItems = editor.CheckedItems;
            int count = checkedItems.Count;
            if (count > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append(checkedItems[0].ToString());
                for (int i = 1; i < count; i++)
                {
                    sb.Append(", ");
                    sb.Append(checkedItems[i].ToString());
                }
                return sb.ToString();
            }

        }
        return null;
    }

    public override void SetEditorValue(object value)
    {
        if (SubEditor is CheckedListBoxSubEditor editor)
        {
            editor.ClearSelected();

            if (value is string text)
            {
                string[] items = text.Split(',', (char)StringSplitOptions.RemoveEmptyEntries);
                foreach (string item in items)
                {
                    int index = editor.FindString(item.Trim());
                    if (index >= 0)
                    {
                        editor.SetItemChecked(index, true);
                    }
                }
            }
        }
    }

    public object[] Items { get; set; }
}
public class CheckedListBoxSubEditor : CheckedListBox, ISubEditor, ISubEditorParentInfo
{
    public CheckedListBoxSubEditor()
    {
        SelectionMode = SelectionMode.One;
    }

    public Control EditorControl { get; set; }

    public event EventHandler ValueChanged;
    public event EventHandler CloseUp;

    public Point GetLocation(Rectangle rect)
    {
        return Point.Empty;
    }

    public Size GetPreferredSize()
    {
        Size size = GetPreferredSize(Size.Empty);
        if (EditorControl != null)
        {
            size.Width = EditorControl.Width;
        }
        return size;
    }

    public Control GetSubEditorControl()
    {
        return this;
    }

    public object GetValue()
    {
        return SelectedValue;
    }

    public void SetValue(object value)
    {
        SelectedValue = value;
    }
}

위 코드를 사용하면 아래와 같이 나타납니다.

f42a9160b932a83164946a55aeb0139b_1631605222_4053.gif
 

다른 궁금한 점이 생기면, 언제든 문의 주시기 바랍니다.


감사합니다.

그레이프시티 드림

* 그레이프시티(GrapeCity)는 개발자를 위하여 ComponentOne(컴포넌트원), Spread(스프레드), ActiveReports(액티브리포츠), SpreadJS(스프레드JS), Wijmo(위즈모)와 같은 엑셀 스프레드시트 리포팅 그리드와 차트 등 다양한 종류의 .NET JavaScript(자바스크립트) 컴포넌트 툴을 생산하고있는 개발툴 전문 회사 입니다.

댓글목록

등록된 댓글이 없습니다.

메시어스 홈페이지를 통해 제품에 대해서 더 자세히 알아 보세요!
홈페이지 바로가기
메시어스 홈페이지를 통해 제품에 대해서 더 자세히 알아 보세요!
홈페이지 바로가기
이메일 : sales-kor@mescius.com | 전화 : 1670-0583 | 경기도 과천시 과천대로 7길 33, 디테크타워 B동 1107호 메시어스(주) 대표자 : 허경명 | 사업자등록번호 : 123-84-00981 | 통신판매업신고번호 : 2013-경기안양-00331 ⓒ 2024 MESCIUS inc. All rights reserved.