I have been trying to solve this for a week now. Keep having handling a custom gridviewcell. here the problem, I want to have a cell in my datagridview that is a user control. I want a be able to use my control and save the final result in the currentcell (row,column). I can use either the TAG or the Value it dosen't matter.
Finally here's my code : Good luck it give it my headache.
public class MultiBoxListCell : DataGridViewTextBoxCell
{
Dictionary<int,>>> MycacheSaved;
public MultiBoxListCell(): base()
{
}
protected override void OnEnter(int rowIndex, bool throughMouseClick)
{
this.OwningRow.Height = 120;
base.OnEnter(rowIndex, throughMouseClick);
}
protected override void OnLeave(int rowIndex, bool throughMouseClick)
{
this.OwningRow.Height = 22;
base.OnLeave(rowIndex, throughMouseClick);
}
public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
MultiBoxListEditingControl CTRL = this.DataGridView.EditingControl as MultiBoxListEditingControl;
List<package> DPack = this.DataGridView.Rows[rowIndex].Cells[9].Value as List<package>;
CTRL.ShowPackages(DPack);
}
public override Type EditType
{
get
{
return typeof(MultiBoxListEditingControl);
}
}
public override Type ValueType
{
get
{
return typeof(List<package>);
}
}
public override object DefaultNewRowValue
{
get
{
return null;
}
}
public class MultiBoxListEditingControl : MultiBoxList, IDataGridViewEditingControl
{
DataGridView dataGridView;
bool valueChanged = false;
int rowIndex;
public MultiBoxListEditingControl()
{
this.NameText = "Packages: ";
}
public void ShowPackages(List<package> Packages)
{
List<boxitem> Boxitems = BoxPackage.BOXPackages(Packages);
FillItems(Boxitems);
}
public override void FillItems(List<boxitem> items)
{
List<boxitem> BottomList = new List<boxitem>();
base.FillItems(items);
foreach (BoxItem selecteditem in items)
{
if (selecteditem.selected)
{
BottomList.Add(selecteditem);
}
}
base.FillItemsAlreadySelected(BottomList);
}
public object EditingControlFormattedValue
{
get
{
return this.GetCompletePackagesInfo();
}
set
{
}
}
public object GetEditingControlFormattedValue(
DataGridViewDataErrorContexts context)
{
return EditingControlFormattedValue;
}
public void ApplyCellStyleToEditingControl(
DataGridViewCellStyle dataGridViewCellStyle)
{
this.Font = dataGridViewCellStyle.Font;
}
public int EditingControlRowIndex
{
get
{
return rowIndex;
}
set
{
rowIndex = value;
}
}
public bool EditingControlWantsInputKey(
Keys key, bool dataGridViewWantsInputKey)
{
switch (key & Keys.KeyCode)
{
case Keys.Left:
case Keys.Up:
case Keys.Down:
case Keys.Right:
case Keys.Home:
case Keys.End:
case Keys.PageDown:
case Keys.PageUp:
return true;
default:
return false;
}
}
public void PrepareEditingControlForEdit(bool selectAll)
{
}
public bool RepositionEditingControlOnValueChange
{
get
{
return false;
}
}
public DataGridView EditingControlDataGridView
{
get
{
return dataGridView;
}
set
{
dataGridView = value;
}
}
public bool EditingControlValueChanged
{
get
{
return valueChanged;
}
set
{
valueChanged = value;
}
}
public Cursor EditingPanelCursor
{
get
{
return base.Cursor;
}
}
protected override void OnValueChanged(EventArgs eventargs)
{
valueChanged = true;
base.OnValueChanged(eventargs);
}
[edit]SHOUTING removed - OriginalGriff[/edit]