or
private void SetFilter(GridKnownFunction filterFnType, string searchInput) { FilterExpression filter; string input = searchInput.Trim(); if (!string.IsNullOrEmpty(input)) { foreach (GridViewDataColumn column in this._GridTextColumns) { filter = new FilterExpression(FilterExpression.BinaryOperation.OR, filterFnType, "@FilterEditor1"); filter.Parameters.Add("@FilterEditor1", input); column.FilterDescriptor = filter; } } else { this.grid_Data.MasterTemplate.FilterDescriptors.Clear(); } }
Hi
I created my custom cell and column:
Cell:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Telerik.WinControls.UI; using System.Windows.Forms; using System.Drawing; using System.Diagnostics; namespace GridViewUnboundMode { public class EditableCheckBoxCellElement : GridDataCellElement { private RadCheckBoxElement _chk; private RadTextBoxElement _txtBox; private RadLabelElement _lbl; public EditableCheckBoxCellElement(GridViewColumn column, GridRowElement row) : base(column, row) { } protected override void CreateChildElements() { base.CreateChildElements(); _chk = new RadCheckBoxElement(); _chk.Margin = new Padding(0, 2, 0, 0); _chk.MinSize = new Size(20, 20); _chk.Text = string.Empty; _chk.ToggleState = Telerik.WinControls.Enumerations.ToggleState.Off; _chk.ToggleStateChanged += new StateChangedEventHandler(_chk_ToggleStateChanged); _txtBox = new RadTextBoxElement(); _txtBox.Margin = new Padding(0, 2, 0, 0); _txtBox.MinSize = new Size(10, 20); _txtBox.Text = "sss"; _lbl = new RadLabelElement(); _lbl.Text = "Not assigned"; _lbl.Margin = new Padding(0, 4, 0, 0); _lbl.MinSize = new Size(1, 20); _lbl.TextWrap = false; _lbl.Font = new Font(_lbl.Font.Name, _lbl.Font.Size, FontStyle.Italic); _lbl.ForeColor = Color.Gray; this.Children.Add(_chk); this.Children.Add(_lbl); } void _chk_ToggleStateChanged(object sender, StateChangedEventArgs args) { if (_chk.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On) { if (this.Children.Contains(_lbl)) { this.Children.Remove(_lbl); } this.Children.Add(_txtBox); } else if (_chk.ToggleState == Telerik.WinControls.Enumerations.ToggleState.Off) { if (this.Children.Contains(_txtBox)) { this.Children.Remove(_txtBox); } this.Children.Add(_lbl); } } protected override SizeF ArrangeOverride(SizeF finalSize) { if (this.Children.Count == 2) { this.Children[0].Arrange(new RectangleF(0, 0, 20, 20)); this.Children[1].Arrange(new RectangleF(21, 0, finalSize.Width - 28, 20)); if (this.Children[1] == _lbl) { _lbl.MinSize = new Size(Convert.ToInt32(finalSize.Width - 28), 20); } } return finalSize; } public override object Value { get { return _txtBox.Text; } set { _txtBox.Text = value.ToString(); } } public bool IsChecked { get { return _chk.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On; } set { if (value) { _chk.ToggleState = Telerik.WinControls.Enumerations.ToggleState.On; } else { _chk.ToggleState = Telerik.WinControls.Enumerations.ToggleState.Off; } } } } }
Column:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Telerik.WinControls.UI; namespace GridViewUnboundMode { public class EditableCheckBoxColumn : GridViewDataColumn { public EditableCheckBoxColumn(): base() { } public override Type GetCellType(GridViewRowInfo row) { if (row is GridViewDataRowInfo) { return typeof(EditableCheckBoxCellElement); } return base.GetCellType(row); } } }
When I create new row I do something like this:
private void btnAddNewRows_Click(object sender, EventArgs e) { GridViewRowInfo rowInfo = this.radGridView1.Rows.AddNew(); int columnIndex = 0; int rowIndex = rowInfo.Index; foreach (GridViewCellInfo cellInfo in rowInfo.Cells) { cellInfo.Value = string.Format("{0}-{1}", columnIndex, rowIndex); columnIndex++; } }
The problem is that in this loop when I set GridViewCellInfo.Value to some value, property EditableCheckBoxCellElement.Value is not set to this value.
I also don`t know how to get access to EditableCheckBoxCellElement because I need to control property EditableCheckBoxCellElement.IsChecked.
How can I control values for controls that are inside my EditableCheckBoxCellElement?
Data binding is not an option in my case.
Regards
namespace WindowsFormsApplication3{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private RadMenuItem mnuAdd = new RadMenuItem("Add"); private void radGridView1_ContextMenuOpening(object sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e) { e.ContextMenu.Items.Add(mnuAdd); } private void Form1_Load(object sender, EventArgs e) { mnuAdd.Click += new EventHandler(mnuAdd_Click); radGridView1.Rows.AddNew().Tag = false; radGridView1.Rows.AddNew().Tag = false; } void mnuAdd_Click(object sender, EventArgs e) { foreach (GridViewRowInfo row in radGridView1.SelectedRows) { row.Tag = !((bool)row.Tag); row.Cells[0].Value = row.Tag; } } }}foreach (GridViewRowInfo row in radGridView1.SelectedRows)for (int a = 0; a < radGridView1.SelectedRows.Count; a++){ radGridView1.SelectedRows[a].Tag = !((bool)radGridView1.SelectedRows[a].Tag); radGridView1.SelectedRows[a].Cells[0].Value = radGridView1.SelectedRows[a].Tag;}radGridView1.SelectedRows only have one row, the one where i right click and is the only one that got changed.