안녕하세요 그레이프시티입니다.
해당 기능이 기본적으로 제공되진 않지만 아래 코드를 사용하여 구현이 가능합니다.
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;
}
}
위 코드를 사용하면 아래와 같이 나타납니다.
다른 궁금한 점이 생기면, 언제든 문의 주시기 바랍니다.
감사합니다.
그레이프시티 드림
* 그레이프시티(GrapeCity)는 개발자를 위하여 ComponentOne(컴포넌트원), Spread(스프레드), ActiveReports(액티브리포츠), SpreadJS(스프레드JS), Wijmo(위즈모)와 같은 엑셀 스프레드시트 리포팅 그리드와 차트 등 다양한 종류의 .NET JavaScript(자바스크립트) 컴포넌트 툴을 생산하고있는 개발툴 전문 회사 입니다.