Hello,
I created a custom column and cell in my grid following the progress-bar example
https://docs.telerik.com/devtools/winforms/controls/gridview/cells/creating-custom-cells
But I have modified it so that I can view either a textBoxElement or a dropDownListElement depending on what data is in the cell. It all seems to work just fine until I scroll the grid. Scrolling visualy shuffles the data in the custom column. I've tried to take the cell-formatting route but without success. Is it possible to achieve this result somehow?
Public Class GridParameterValueElement Inherits GridDataCellElement Public Sub New(ByVal column As GridViewColumn, ByVal row As GridRowElement) MyBase.New(column, row) End Sub Private isInitialized As Boolean Private firstTimeIndexChanged As Boolean = True Private dropDown As RadDropDownListElement Private textBox As RadTextBoxElement Protected Overrides Sub CreateChildElements() MyBase.CreateChildElements() dropDown = New RadDropDownListElement() With { .DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList } textBox = New RadTextBoxElement() With { .Enabled = True, .ClickMode = Telerik.WinControls.ClickMode.Press, .ZIndex = -1 } If Me.Children.Contains(dropDown) Then Me.Children.Remove(dropDown) If Me.Children.Contains(textBox) Then Me.Children.Remove(textBox) Me.Children.Add(dropDown) Me.Children.Add(textBox) AddHandler dropDown.SelectedIndexChanged, AddressOf SelectedIndexChanged AddHandler textBox.TextChanged, AddressOf TextInBoxChanged 'AddHandler textBox.Click, AddressOf TextBox_Click End Sub Protected Overrides Sub DisposeManagedResources() RemoveHandler dropDown.SelectedIndexChanged, AddressOf SelectedIndexChanged RemoveHandler textBox.TextChanged, AddressOf TextInBoxChanged MyBase.DisposeManagedResources() End Sub 'Private Sub TextBox_Click(sender As Object, e As EventArgs) ' Dim test = sender 'End Sub Public Overrides Sub SetContent() MyBase.SetContent() If Me.RowInfo.Cells("DisplayValue").Tag IsNot Nothing Then If Not Me.isInitialized Then If Me.Children.Contains(textBox) Then Me.Children.Remove(textBox) With Me.dropDown .DataSource = Me.RowInfo.Cells("DisplayValue").Tag .ValueMember = ("DevelopmentTypeParameterValueId") .DisplayMember = ("ParameterValue") End With End If If Me.RowInfo.Tag IsNot Nothing Then RemoveHandler dropDown.SelectedIndexChanged, AddressOf SelectedIndexChanged dropDown.SelectedIndex = DirectCast(Me.RowInfo.Tag, Integer) AddHandler dropDown.SelectedIndexChanged, AddressOf SelectedIndexChanged Else RemoveHandler dropDown.SelectedIndexChanged, AddressOf SelectedIndexChanged dropDown.SelectedIndex = -1 AddHandler dropDown.SelectedIndexChanged, AddressOf SelectedIndexChanged End If ElseIf Me.Value IsNot Nothing AndAlso Me.Value IsNot DBNull.Value Then If Not Me.isInitialized Then If Me.Children.Contains(dropDown) Then Me.Children.Remove(dropDown) Me.textBox.Text = CStr(Me.Value) End If End If Me.isInitialized = True End Sub Protected Overrides ReadOnly Property ThemeEffectiveType() As Type Get Return GetType(GridDataCellElement) End Get End Property Public Overrides Function IsCompatible(ByVal data As GridViewColumn, ByVal context As Object) As Boolean Return TypeOf data Is GridViewParameterValueColumn AndAlso TypeOf context Is GridDataRowElement End Function End Class Public Class GridViewParameterValueColumn Inherits GridViewDataColumn Public Sub New(ByVal fieldName As String) MyBase.New(fieldName) End Sub Public Overrides Function GetCellType(ByVal row As GridViewRowInfo) As Type If TypeOf row Is GridViewDataRowInfo Then Return GetType(GridParameterValueElement) End If Return MyBase.GetCellType(row) End Function End Class
I Have One GridViewTextBox Column in a grid and One ComboBox Column based on selection in a combobox column I need cells of TextBox Column to contain either string or integer value how I can do this please help me.
already used below mentioned code but having issue with that I cannot able to put values more than 100 in that and getting up/down arrows to increases and decrease values but I dont need them.
radGridView1.EditorRequired += new Telerik.WinControls.UI.EditorRequiredEventHandler(radGridView1_EditorRequired); // binding event on grid
void radGridView1_EditorRequired(object sender, Telerik.WinControls.UI.EditorRequiredEventArgs e)
{
if (this.radGridView1.Columns[1].IsCurrent)
{
var a = TextCodes.SingleOrDefault(t => t.Name.Equals(this.radGridView1.CurrentRow.Cells[0].Value));
if (a == null)
return;
if (a.TextCodeType == TextCodeTypeEnum._datetime)
{
e.Editor = new RadDateTimeEditor();
e.EditorType = typeof(RadDateTimeEditor);
}
else if (a.TextCodeType == TextCodeTypeEnum._string && a.TextCodeValueList == null)
{
e.Editor = new RadTextBoxEditor();
e.EditorType = typeof(RadTextBoxEditor);
}
else if (a.TextCodeType == TextCodeTypeEnum._string && a.TextCodeValueList != null)
{
e.Editor = new RadDropDownListEditor();
try
{
((RadDropDownListEditor)e.Editor).DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList;
}
catch (System.Exception)
{
}
e.EditorType = typeof(RadDropDownListEditor);
}
else if (a.TextCodeType == TextCodeTypeEnum._number)
{
e.Editor = new GridSpinEditor();
e.EditorType = typeof(GridSpinEditor);
}
}
}