Hello
I succeeded to put a listview in a cell of a grid. But I have some problems with it.
1. Why the first listview item is always highlighted.
2. How can I add the possibility to work with keyboard to select some listview items instead of mouse.
public class CheckListBoxCellElement : GridDataCellElement
{
public CheckListBoxCellElement(GridViewColumn column, GridRowElement row)
: base(column, row)
{
}
RadListViewElement radListElement;
protected override void CreateChildElements()
{
base.CreateChildElements();
radListElement = new RadListViewElement();
radListElement.ShowCheckBoxes = true;
radListElement.AllowArbitraryItemHeight = true;
radListElement.ViewType = ListViewType.IconsView;
radListElement.VisualItemFormatting += new ListViewVisualItemEventHandler(radListElement_VisualItemFormatting);
radListElement.ItemCheckedChanged += new ListViewItemEventHandler(radListElement_ItemCheckedChanged);
this.Children.Add(radListElement);
}
void radListElement_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
{
BaseListViewVisualItem lvi = e.VisualItem as BaseListViewVisualItem;
lvi.DrawBorder = true;
lvi.DrawFill = true;
lvi.CanFocus = true;
}
void radListElement_ItemCheckedChanged(object sender, ListViewItemEventArgs e)
{
if (e.Item.CheckState == Telerik.WinControls.Enumerations.ToggleState.On)
{
PropertyValue val = (PropertyValue)e.Item.DataBoundItem;
val.Selected = true;
}
else
{
PropertyValue val = (PropertyValue)e.Item.DataBoundItem;
val.Selected = false;
}
}
protected override void SetContentCore(object value)
{
IList list = (IList)value;
radListElement.DataSource = list;
radListElement.DisplayMember = "Name";
radListElement.ValueMember = "ID";
}
protected override Type ThemeEffectiveType
{
get
{
return typeof(GridDataCellElement);
}
}
public override bool IsCompatible(GridViewColumn data, object context)
{
return data is CheckListBoxColumn && context is GridDataRowElement;
}
}
public class CheckListBoxColumn : GridViewDataColumn
{
public CheckListBoxColumn(string fieldName)
: base(fieldName)
{
}
public override Type GetCellType(GridViewRowInfo row)
{
if (row is GridViewDataRowInfo)
{
return typeof(CheckListBoxCellElement);
}
return base.GetCellType(row);
}
}
public class Data
{
public string Name { get; set; }
public IList Field { get; set; }
}
public partial class MYForm : Form
{
public MYForm()
{
InitializeComponent();
Init();
}
private void Init()
{
GridViewTextBoxColumn column1 = new GridViewTextBoxColumn("Name");
ksGrid.Columns.Add(column1);
CheckListBoxColumn column2 = new CheckListBoxColumn("Field");
ksGrid.Columns.Add(column2);
column2.Width = 250;
ksGrid.AutoGenerateColumns = false;
ArrayList list = new ArrayList();
IList values1 = new ArrayList();
values1.Add(new PropertyValue() { ID = 1, Name = "Blue" });
values1.Add(new PropertyValue() { ID = 2, Name = "Yellow" });
values1.Add(new PropertyValue() { ID = 3, Name = "Red" });
Data data1 = new Data { Name = "Color", Field = values1 };
list.Add(data1);
IList values2 = new ArrayList();
values2.Add(new PropertyValue() { ID = 4, Name = "M" });
values2.Add(new PropertyValue() { ID = 5, Name = "L" });
values2.Add(new PropertyValue() { ID = 6, Name = "XL" });
Data data2 = new Data { Name = "Size", Field = values2 };
list.Add(data2);
ksGrid.DataSource = list;
object ob = ksGrid.Rows[1];
}