9 Answers, 1 is accepted
0
Hello Jiri,
Thank you for contacting Telerik Support.
In order to achieve the desired behavior, it is necessary to create a custom column, which uses two custom cells. Here is a sample approach how to implement one column which uses CustomComboCell for each odd row and CustomCommandCell for each even cell. The editor for the CustomComboCell is a RadDropDownListEditor which is populated in the CellEditorInitialized.
You can find more information about implementing custom cells in our Creating custom cells help article.
I hope this information helps. Should you have further questions, I would be glad to help.
Regards,
Desislava
Telerik
Thank you for contacting Telerik Support.
In order to achieve the desired behavior, it is necessary to create a custom column, which uses two custom cells. Here is a sample approach how to implement one column which uses CustomComboCell for each odd row and CustomCommandCell for each even cell. The editor for the CustomComboCell is a RadDropDownListEditor which is populated in the CellEditorInitialized.
public partial class Form1 : Form{ public Form1() { InitializeComponent(); GridViewTextBoxColumn textBoxColumn = new GridViewTextBoxColumn("Text"); radGridView1.Columns.Add(textBoxColumn); GridViewCheckBoxColumn checkBoxColumn = new GridViewCheckBoxColumn("Value"); radGridView1.Columns.Add(checkBoxColumn); CustomColumn newColumn = new CustomColumn("NewColumn"); radGridView1.Columns.Add(newColumn); for (int i = 0; i < 20; i++) { this.radGridView1.Rows.Add("Test" + i, i % 2 == 0, null); } this.radGridView1.CellEditorInitialized += radGridView1_CellEditorInitialized; this.radGridView1.CellBeginEdit += radGridView1_CellBeginEdit; } private void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e) { GridViewEditManager manager = sender as GridViewEditManager; if (manager.GridViewElement.GridControl.CurrentCell is CustomCommandCell) { e.Cancel = true; } } private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e) { GridViewEditManager manager = sender as GridViewEditManager; if (manager.GridViewElement.GridControl.CurrentCell is CustomComboCell) { RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor; RadDropDownListEditorElement element = editor.EditorElement as RadDropDownListEditorElement; element.DataSource = new List<string>() { "item1", "item2", "item3" }; } }}public class CustomColumn : GridViewDataColumn{ public CustomColumn(string fieldName) : base(fieldName) { } public override Type GetCellType(GridViewRowInfo row) { if (row is GridViewDataRowInfo) { if (row.Index % 2 == 0) { return typeof(CustomComboCell); } else { return typeof(CustomCommandCell); } } return base.GetCellType(row); } public override Type GetDefaultEditorType() { return typeof(RadDropDownListEditor); }}public class CustomComboCell : GridDataCellElement{ public CustomComboCell(GridViewColumn column, GridRowElement row) : base(column, row) { } protected override Type ThemeEffectiveType { get { return typeof(GridDataCellElement); } } public override bool IsCompatible(GridViewColumn data, object context) { return data is CustomColumn && context is GridDataRowElement; }}public class CustomCommandCell : GridDataCellElement{ private RadButtonElement button; public CustomCommandCell(GridViewColumn column, GridRowElement row) : base(column, row) { base.CreateChildElements(); this.button = new RadButtonElement(); this.button.Text = "Click me"; this.button.Click += new EventHandler(Button_Click); this.Children.Add(button); } protected override Type ThemeEffectiveType { get { return typeof(GridDataCellElement); } } public override bool IsCompatible(GridViewColumn data, object context) { return data is CustomColumn && context is GridDataRowElement; } private void Button_Click(object sender, EventArgs e) { MessageBox.Show("Clicked"); }}You can find more information about implementing custom cells in our Creating custom cells help article.
I hope this information helps. Should you have further questions, I would be glad to help.
Regards,
Desislava
Telerik
TRY TELERIK'S NEWEST PRODUCT - APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Rawad
Top achievements
Rank 2
answered on 26 Jun 2014, 10:56 AM
Hi Desisalva
Could you please re-write your post in VB.net and not in c# in order to try it.
Thanks
Could you please re-write your post in VB.net and not in c# in order to try it.
Thanks
0
Hello Rawad,
Thank you for writing.
Here is the code snippet in VB.NET:
Please feel free to use our free online converter.
I hope this information helps. Should you have further questions, I would be glad to help.
Regards,
Desislava
Telerik
Thank you for writing.
Here is the code snippet in VB.NET:
Partial Public Class Form1Inherits Form Public Sub New() InitializeComponent() Dim textBoxColumn As New GridViewTextBoxColumn("Text") RadGridView1.Columns.Add(textBoxColumn) Dim checkBoxColumn As New GridViewCheckBoxColumn("Value") RadGridView1.Columns.Add(checkBoxColumn) Dim newColumn As New CustomColumn("NewColumn") RadGridView1.Columns.Add(newColumn) Me.RadGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill For i As Integer = 0 To 19 Me.RadGridView1.Rows.Add("Test" & i, i Mod 2 = 0, Nothing) Next AddHandler Me.RadGridView1.CellEditorInitialized, AddressOf radGridView1_CellEditorInitialized AddHandler Me.RadGridView1.CellBeginEdit, AddressOf radGridView1_CellBeginEdit AddHandler Me.RadGridView1.CurrentCellChanged, AddressOf radGridView1_CurrentCellChanged End Sub Private Sub radGridView1_CurrentCellChanged(sender As Object, e As CurrentCellChangedEventArgs) Dim grid As RadGridView = TryCast(sender, RadGridView) Dim current = grid.CurrentCell End Sub Private Sub radGridView1_CellBeginEdit(sender As Object, e As GridViewCellCancelEventArgs) Dim manager As GridViewEditManager = TryCast(sender, GridViewEditManager) If TypeOf manager.GridViewElement.GridControl.CurrentCell Is CustomCommandCell Then e.Cancel = True End If End Sub Private Sub radGridView1_CellEditorInitialized(sender As Object, e As GridViewCellEventArgs) Dim manager As GridViewEditManager = TryCast(sender, GridViewEditManager) If TypeOf manager.GridViewElement.GridControl.CurrentCell Is CustomComboCell Then Dim editor As RadDropDownListEditor = TryCast(e.ActiveEditor, RadDropDownListEditor) Dim element As RadDropDownListEditorElement = TryCast(editor.EditorElement, RadDropDownListEditorElement) element.DataSource = New List(Of String)() From { _ "item1", _ "item2", _ "item3" _ } End If End SubEnd ClassPublic Class CustomColumnInherits GridViewDataColumn Public Sub New(fieldName As String) MyBase.New(fieldName) End Sub Public Overrides Function GetCellType(row As GridViewRowInfo) As Type If TypeOf row Is GridViewDataRowInfo Then If row.Index Mod 2 = 0 Then Return GetType(CustomComboCell) Else Return GetType(CustomCommandCell) End If End If Return MyBase.GetCellType(row) End Function Public Overrides Function GetDefaultEditorType() As Type Return GetType(RadDropDownListEditor) End FunctionEnd ClassPublic Class CustomComboCellInherits GridDataCellElement Public Sub New(column As GridViewColumn, row As GridRowElement) MyBase.New(column, row) End Sub Protected Overrides ReadOnly Property ThemeEffectiveType() As Type Get Return GetType(GridDataCellElement) End Get End Property Public Overrides Function IsCompatible(data As GridViewColumn, context As Object) As Boolean Return TypeOf data Is CustomColumn AndAlso TypeOf context Is GridDataRowElement End FunctionEnd ClassPublic Class CustomCommandCellInherits GridDataCellElement Private button As RadButtonElement Public Sub New(column As GridViewColumn, row As GridRowElement) MyBase.New(column, row) MyBase.CreateChildElements() Me.button = New RadButtonElement() Me.button.Text = "Click me" AddHandler Me.button.Click, AddressOf Button_Click Me.Children.Add(button) End Sub Protected Overrides ReadOnly Property ThemeEffectiveType() As Type Get Return GetType(GridDataCellElement) End Get End Property Public Overrides Function IsCompatible(data As GridViewColumn, context As Object) As Boolean Return TypeOf data Is CustomColumn AndAlso TypeOf context Is GridDataRowElement End Function Private Sub Button_Click(sender As Object, e As EventArgs) MessageBox.Show("Clicked") End SubPlease feel free to use our free online converter.
I hope this information helps. Should you have further questions, I would be glad to help.
Regards,
Desislava
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
0
Rawad
Top achievements
Rank 2
answered on 01 Jul 2014, 05:31 AM
Dear Desislava
Thanks a lot.
It's well working with me, but how to make from the code above, the combobox not editable, just selective field, in another term user cannot write in this field, but just select an item from the list (item1, item2, item3)
Thanks
Thanks a lot.
It's well working with me, but how to make from the code above, the combobox not editable, just selective field, in another term user cannot write in this field, but just select an item from the list (item1, item2, item3)
Thanks
0
Rawad
Top achievements
Rank 2
answered on 01 Jul 2014, 11:28 AM
Dear Desislava
Hope this post finds you well.
I tried to insert the following line in the cellEditorInitialized and it's working.
element.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList
I tried the code above, written in VB.net, but I changed the Button_Click Events to display the value of the first cell, so I added the following lines :
Me.button.Tag = row.RowInfo.Cells(0).Value
Me.button.Text = "Click me: " & row.RowInfo.Cells(0).Value
in the class CustomCommandCell Under the sub New.
and the sub
Private Sub Button_Click(sender As Object, e As EventArgs)
MessageBox.Show(sender.Tag)
End Sub
If the radgridview is big (no scroll bar are visible), the data are well displayed, meanwhile if the radgridview is small (scroll bar is visible), the data is not well displayed.
please check the attached file for more details, there's a solution ?
Thanks
Hope this post finds you well.
I tried to insert the following line in the cellEditorInitialized and it's working.
element.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList
I tried the code above, written in VB.net, but I changed the Button_Click Events to display the value of the first cell, so I added the following lines :
Me.button.Tag = row.RowInfo.Cells(0).Value
Me.button.Text = "Click me: " & row.RowInfo.Cells(0).Value
in the class CustomCommandCell Under the sub New.
and the sub
Private Sub Button_Click(sender As Object, e As EventArgs)
MessageBox.Show(sender.Tag)
End Sub
If the radgridview is big (no scroll bar are visible), the data are well displayed, meanwhile if the radgridview is small (scroll bar is visible), the data is not well displayed.
please check the attached file for more details, there's a solution ?
Thanks
0
Hello Rawad,
Thank you for writing back.
Regards,
Desislava
Telerik
Thank you for writing back.
- The DropDownStyle property determines if the text area at the top of the RadDropDownListEditor can be edited. A setting of DropDown (the default) allows editing and the DropDownList setting shows the text area as read-only.
- Due to the UI virtualization in RadGridView, cell elements are created only for currently visible cells and are being reused during operations like scrolling, filtering, grouping and so on.
In order to prevent applying the formatting to other columns' cell elements (because of the cell reuse) all customization should be reset for the rest of the cell elements. Thus, the RadButtonElement.Text will not be displayed where is redundant:PrivateSubButton_Click(senderAsObject, eAsEventArgs)DimbtnAsRadButtonElement = TryCast(sender, RadButtonElement)DimcellAsGridDataCellElement = TryCast(btn.Parent, GridDataCellElement)Ifcell IsNotNothingThenbtn.Text = cell.RowInfo.Cells(0).Valuecell.RowInfo.Tag ="clicked"EndIfEndSubPublicOverridesSubSetContent()MyBase.SetContent()IfMe.button IsNotNothingThenIfMe.RowInfo.Tag ="clicked"ThenMe.button.Text =Me.RowInfo.Cells(0).ValueElseMe.button.Text ="Click me"EndIfEndIfEndSub
Regards,
Desislava
Telerik
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
0
Bao
Top achievements
Rank 1
answered on 26 Jul 2017, 04:23 PM
Hi,
How can i access GridDataCellElement from GridViewDataColumn.
I have a case, i have a gridview with 3 custom checkbox column. after binding completely, when i click button, i want to set check or uncheck custom checkbox column by loop the gridview rows. But i can not access to the cell element by using loop.
0
Bao
Top achievements
Rank 1
answered on 26 Jul 2017, 04:25 PM
and because my gridview is self hierarchy when i use it:
gridview.TableElement.GetCellElement in loop rows. it only gets the parent row, about the child row is collapsed. it can not access.
0
Hello Bao,
Thank you for writing.
Your question has already been answered in this thread. Please, see our answer there for more information.
We kindly ask you to use just one thread for a specific problem to contact us. Posting the same questions numerous times slows down our response time because we will need to review and address two or more tickets instead of one. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.
Thank you for your understanding.
Regards,
Dess
Progress Telerik
Thank you for writing.
Your question has already been answered in this thread. Please, see our answer there for more information.
We kindly ask you to use just one thread for a specific problem to contact us. Posting the same questions numerous times slows down our response time because we will need to review and address two or more tickets instead of one. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.
Thank you for your understanding.
Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
