| Public Class RadForm1 |
| Private _cellModifyBegin As Boolean |
| Private _currentEditCell As Integer |
| Private Sub RadForm1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
| _cellModifyBegin = False |
| Try |
| grdCustomers.EnterKeyMode = Telerik.WinControls.UI.RadGridViewEnterKeyMode.None |
| Me.CustomerTableAdapter.Fill(Me.CustomerApps.Customer) |
| Catch ex1 As System.Exception |
| Debug.WriteLine(String.Format("Failed in frmMain2.frmMain2_Load - Exception: {0}", ex1.ToString())) |
| My.Application.Log.WriteException(ex1) |
| MessageBox.Show(String.Format("An error has ocurred. Message : {0}", ex1.Message())) |
| Finally |
| Debug.WriteLine("End ---> frmMain2.frmMain2_Load") |
| My.Application.Log.WriteEntry(String.Format("End ---> {0:00}:{1:00}:{2:00}:{3:0000} frmMain2.frmMain2_Load", Now.Hour, Now.Minute, Now.Second, Now.Millisecond)) |
| End Try |
| End Sub |
| Private Sub grdCustomers_CellBeginEdit(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCellCancelEventArgs) Handles grdCustomers.CellBeginEdit |
| Debug.Print(String.Format("grdCustomers_CellBeginEdit. RowIndex={0}, CellIndex={1}", e.RowIndex, e.ColumnIndex)) |
| If _currentEditCell <> e.ColumnIndex Then |
| ' this cell got into Edit mode due to user tabbing away from a previous cell edit |
| e.Cancel = True |
| Return |
| End If |
| _cellModifyBegin = True |
| End Sub |
| Private Sub grdCustomers_CellDoubleClick(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles grdCustomers.CellDoubleClick |
| Debug.Print(String.Format("grdCustomers_CellDoubleClick. RowIndex={0}, CellIndex={1}", e.RowIndex, e.ColumnIndex)) |
| _currentEditCell = e.ColumnIndex |
| e.Row.Cells(e.ColumnIndex).BeginEdit() |
| End Sub |
| Private Sub grdCustomers_CellEndEdit(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles grdCustomers.CellEndEdit |
| If grdCustomers.ActiveEditor.IsModified Then |
| Debug.Print(String.Format("grdCustomers_CellEndEdit. RowIndex={0}, CellIndex={1}", e.RowIndex, e.ColumnIndex)) |
| CustomerTableAdapter.Update(CustomerApps.Customer) |
| grdCustomers.Update() |
| End If |
| _cellModifyBegin = False |
| End Sub |
| End Class |
Hi!
VERSION: 2010 Q2 SP2
This is my simple application:
EditableCheckBoxCellElement:
namespace GridViewUnboundMode { public class EditableCheckBoxCellElement : GridDataCellElement { private RadCheckBoxElement _chk; private RadTextBoxElement _txtBox; private CellValue _cellValue; public EditableCheckBoxCellElement(GridViewColumn column, GridRowElement row) : base(column, row) { } protected override void CreateChildElements() { base.CreateChildElements(); _chk = new RadCheckBoxElement(); _chk.Margin = new Padding(2, 2, 2, 2); _chk.MinSize = new Size(10, 10); _chk.Text = string.Empty; _chk.ToggleState = Telerik.WinControls.Enumerations.ToggleState.Off; _chk.ToggleStateChanged += new StateChangedEventHandler(_chk_ToggleStateChanged); _txtBox = new RadTextBoxElement(); _txtBox.Margin = new Padding(2, 2, 2, 2); _txtBox.MinSize = new Size(10, 10); _txtBox.Text = "sss"; this.Children.Add(_chk); this.Children.Add(_txtBox); } void _chk_ToggleStateChanged(object sender, StateChangedEventArgs args) { if (_chk.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On) { _cellValue.IsAssigned = true; } else if (_chk.ToggleState == Telerik.WinControls.Enumerations.ToggleState.Off) { _cellValue.IsAssigned = false; } } protected override SizeF ArrangeOverride(SizeF finalSize) { if (this.Children.Count == 2) { this.Children[0].Arrange(new RectangleF(2, 2, 10, 10)); this.Children[1].Arrange(new RectangleF(21, 2, finalSize.Width - 28 - 10, 15)); } return finalSize; } public override object Value { get { return _cellValue; } set { _cellValue = value as CellValue; if (_cellValue != null) { _txtBox.Text = _cellValue.Text; this.IsChecked = _cellValue.IsAssigned; } } } public bool IsChecked { get { return _cellValue.IsAssigned; } set { if (value) { _chk.ToggleState = Telerik.WinControls.Enumerations.ToggleState.On; } else { _chk.ToggleState = Telerik.WinControls.Enumerations.ToggleState.Off; } _cellValue.IsAssigned = value; } } } } EditableCheckBoxColumn:
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); } } } CellValue:
namespace GridViewUnboundMode { public class CellValue { public string Text { get; set; } public bool IsAssigned { get; set; } } }Form1:
namespace GridViewUnboundMode { public partial class Form1 : Form { public Form1() { InitializeComponent(); radGridView1.MultiSelect = true; radGridView1.AllowColumnChooser = false; GridViewDataColumn columnCSname = new GridViewTextBoxColumn(); columnCSname.HeaderText = "Standard column"; radGridView1.Columns.Add(columnCSname); columnCSname.Width = 160; columnCSname.ReadOnly = true; this.AddCustomColumns(4); this.AddNewRow(); this.AddNewRow(); columnCSname.IsPinned = true; } private void AddNewRow() { GridViewRowInfo rowInfo = this.radGridView1.Rows.AddNew(); int columnIndex = 0; foreach (GridViewCellInfo cellInfo in rowInfo.Cells) { if (cellInfo.ColumnInfo.Index == 0) { cellInfo.Value = string.Format("Standard column, Col: {0}, Row: {1}", cellInfo.ColumnInfo.Index, rowInfo.Index); } else { CellValue cellValue = new CellValue(); cellValue.Text = string.Format("Col: {0}, Row: {1}", cellInfo.ColumnInfo.Index, rowInfo.Index); cellInfo.Tag = cellValue; } columnIndex++; } } private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) { EditableCheckBoxCellElement cellElement = e.CellElement as EditableCheckBoxCellElement; if (cellElement != null) { CellValue val = e.CellElement.RowInfo.Cells[e.CellElement.ColumnIndex].Tag as CellValue; cellElement.Value = val; } } private void AddCustomColumns(int count) { for (int index = 0; index < count; index++) { GridViewDataColumn newColumn = new EditableCheckBoxColumn(); newColumn.HeaderText = "Col" + (radGridView1.Columns.Count + 1).ToString(); newColumn.Name = newColumn.HeaderText; newColumn.Width = 120; if (radGridView1.Columns.Count == 0) { newColumn.IsPinned = true; } radGridView1.Columns.Add(newColumn); } } } }
When I run application I see form from attachment viewAfterStartup.JPG. “Standard column” is pinned at left.
FIRST PROBLEM
If I resize window to smaller size then I have scroll bar on the bottom.
When I start scrolling to right I have problem with text box from custom cells – it overlaps on “Standard column”. This is weird because this problem is only for text box, for check box it is ok (check box does not overlap pinned column) – please check attachments “scrollingCheckBox-OK.JPG” and “scrollingTextBox-NOTok.JPG”. What is wrong in my source code?
SECOND PROBLEM
When I unpin “Standard column” I see in this column cells of class EditableCheckBoxCellElement. How it is possible? Name of column is correct but cells change type. Check attachment “unpinnedFirstColumn.JPG”.
Regards

GridViewTemplate template = new GridViewTemplate();template.AllowColumnResize = true;foreach (GridViewColumn col in myGrid.Columns) template.Columns.Add((GridViewDataColumn)col);GridViewInfo info = new GridViewInfo(template);GridViewRowInfo row = new GridViewRowInfo(info);row.AllowResize = true;// oRow contains the values for the cellsfor (int i = 0; i < oRow.Length; i++) row.Cells[i].Value = oRow[i]; row.Tag = epropSample;