Я пытаюсь реализовать Multi Value CheckBox ComboBox в DataGridView
.В некоторой степени это успешно, но когда я оставляю редактирование проверки ячейки, он выдает ошибку.
Вот снимок моего исходного кода: Мой исходный код находится здесь в Google.Drive
Предложения по улучшению приветствуются.снимок экрана 1 выбор в выпадающем списке в порядке просмотра
снимок экрана 2 ошибка проверки при изменении фокуса на другие ячейки
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace PresentationControls
{
public class CheckedComboCell : DataGridViewComboBoxCell //DataGridViewTextBoxCell //
{
public CheckBoxComboBox cboxg;
public CheckedComboCell()
: base()
{
}
public override void InitializeEditingControl(int rowIndex, object
initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
// Set the value of the editing control to the current cell value.
base.InitializeEditingControl(rowIndex, initialFormattedValue,dataGridViewCellStyle);
string ss= initialFormattedValue.ToString();
ss = ss.Replace(" ", string.Empty);
List<string> result = ss.Split(',').ToList();
CheckBoxComboBox chkcb = DataGridView.EditingControl as CheckBoxComboBox;
cboxg = chkcb;
CheckBoxComboBoxItemList ccc = chkcb.CheckBoxItems;
if (chkcb.CheckBoxItems.Count>0)
foreach(string s in result)
{
// if(s!="")
// chkcb.CheckBoxItems[s].Checked = true;
}
else
{
}
}
public override Type EditType
{
get
{
// Return the type of the editing control
Type kk = typeof(CheckBoxComboBox);
return kk;
}
}
// Type of this cell's value.
private static Type defaultValueType = typeof(System.String);
public override Type ValueType
{
get
{
Type valueType = base.ValueType;
if (valueType != null)
{
return valueType;
}
return defaultValueType;
}
}
private string label;
public string Label
{
get
{
return label;
}
set
{
label = value;
}
}
public object list { get; set; }
public string[] DataSource {
set {
if (cboxg != null)
cboxg.DataSource = value;
}
}
protected override bool SetValue(int rowIndex, object value)
{
if (value != null)
{
this.ErrorText = "bbbb";
bool bb = base.SetValue(rowIndex, value);
return bb;
}
return false;
}
}
}