
How can I use a different edit control on different rows, but in the same column? Is this possible?:
Thanks
25 Answers, 1 is accepted

I tried the following:
private void rgrdBRConfigTable_EditorRequired(object sender, EditorRequiredEventArgs e)
{
e.EditorType =
typeof(RadComboBoxEditor);
}
to change it from the defaut textbox to a combobox, but it makes no difference, it still uses the textbox to edit the column... It appears that this event is exactly what I am looking for, but it doesn;t appear to do what I want....
Please, anyone?
Thanks
Rod

I also need to add options to the combobox, and I've tried the following code, but it does not work,...
private void radGridView1_EditorRequired(object sender, Telerik.WinControls.UI.EditorRequiredEventArgs e)
{
e.EditorType =
typeof(RadComboBoxEditor);
RadComboBoxEditor comboEditor = e.Editor as RadComboBoxEditor;
RadComboBoxItem i = new RadComboBoxItem("Green");
comboEditor.Items.Add(i);
}
but I get an error:
Error 1 'Telerik.WinControls.UI.RadComboBoxEditor' does not contain a definition for 'Items'
Thank you for contacting us.
Please refer to the attached sample project which demonstrates how to dynamically change the default editor. It uses EditorRequired and CellBeginEdit events.
Do not hesitate to contact me again if you have any additional questions.
Greetings,
Martin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.


This solution is what I am looking for my grid.
I've downloaded and executed this. When I visit the combobox editor cell in row id 3 for the first time, it displays combo values of 'Code1' thru 'Code5' values. However, when I visit a different cell (text cell or any other cell) and return back to the same cell with combobox editor cell in row id 3, combo does not show any items at all. radGridView1_CellBeingEdit code is being executed but end result is combo with no items shown.
Is this normal? I have not touched any part of your code after download.
Does anyone experience this condition?
Harry Idachi
Thank you for contacting me.
We have done some major changes in the new version of RadGridView (Q2 2010). That is why the old project might not work as expected with the latest Telerik assemblies. Now we are using RadDropDownListEditor instead RadComboBoxEditor. I have made some changes to my previous sample which will allow it to work with the latest RadControls. You can find the modified project as an attachment to this message. I recommend using Q2 2010 SP2 version which was used during my tests.
Do not hesitate to contact me again if you have any additional questions.
Regards,
Martin Vasilev
the Telerik team

For both of us, we still have the same problem.
Click in the cell for the drop down list. It works!
Click in any other cell and go back to the drop down list, the list drops down but is empty.
I attached screen shots in case there is any misunderstanding in what we are seeing.
Any suggestions?

Just change the EditorRequired event to this:
void
radGridView1_EditorRequired(
object
sender, EditorRequiredEventArgs e)
{
if
(
this
.radGridView1.Columns[2].IsCurrent && (
int
)
this
.radGridView1.CurrentRow.Cells[0].Value % 4 == 0)
{
e.EditorType =
typeof
(RadDateTimeEditor);
}
else
if
((
int
)
this
.radGridView1.CurrentRow.Cells[0].Value % 3 == 0)
{
e.Editor =
new
RadDropDownListEditor();
e.EditorType =
typeof
(RadDropDownListEditor);
}
}
Maybe it's a bug, maybe it's a mistake somewhere, also i have to warn you that if you want to have a DropDownList style for the EditorElement here you should use an empty try catch statement because when you change the style from DropDown to DropDownLIst it is throwing an exception (see this thread) for more info.
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga

It works now!
Harry

If the field in the table is set to "Tuesday", and the drop down contains "Monday", "Tuesday", "Wednesday", ... then we want the drop down selection to default to "Tuesday", not the first item in the list.
Is there a way to set the default item in the list?
I tried setting the editorElement.ValueMember to the name of the field, but that did not seem to help.
Thanks!

If the Value for that Cell matches the value for an element in the dropdown, that element is the one selected, please check the value for the cell and the ValueMember for the DropDownListElement.
If this does not solve your problem please let me know and i will provide an example.
Best Regards,
Emanuel Varga

I have not been able to get this to work. Could you provide an example that works within the EditorRequired event you provided for us?

On the example application from above, please change:
void
radGridView1_CellBeginEdit(
object
sender, GridViewCellCancelEventArgs e)
{
RadDropDownListEditor editor =
this
.radGridView1.ActiveEditor
as
RadDropDownListEditor;
if
(editor !=
null
)
//&& ((RadDropDownListEditorElement)comboEditor.EditorElement).DataSource == null)
{
RadDropDownListEditorElement editorElement = ((RadDropDownListEditorElement)editor.EditorElement);
editorElement.DisplayMember =
"codeName"
;
editorElement.ValueMember =
"code"
;
editorElement.DataSource = _ds.Tables[
"Codes"
];
//((RadComboBoxEditorElement)comboEditor.EditorElement).DataSource = _source;
Debug.WriteLine(
"DataSource set"
);
}
}
and :
void
InitializeGrid()
{
DataTable tbl =
new
DataTable(
"MainTable"
);
tbl.Columns.Add(
new
DataColumn(
"id"
,
typeof
(Int32)));
tbl.Columns.Add(
new
DataColumn(
"text"
,
typeof
(String)));
tbl.Columns.Add(
"value"
,
typeof
(
object
));
tbl.PrimaryKey =
new
DataColumn[] { tbl.Columns[
"id"
] };
for
(
int
i = 0; i < 1000; i++)
{
string
textValue;
object
value =
null
;
if
(i % 4 == 0)
{
textValue = String.Format(
"{0}: DateTime editor"
, i + 1);
value = DateTime.Now;
}
else
if
(i % 3 == 0)
{
textValue = String.Format(
"{0}: DropDownList editor"
, i + 1);
value = (i % 5);
}
else
{
textValue = String.Empty;
//String.Format("{0}: default editor", i + 1);
}
tbl.Rows.Add(i, textValue, value);
}
DataTable tbl2 =
new
DataTable(
"Codes"
);
tbl2.Columns.Add(
"code"
,
typeof
(Int32));
tbl2.Columns.Add(
"codeName"
,
typeof
(String));
for
(
int
i = 0; i < 5; i++)
{
tbl2.Rows.Add(i, String.Format(
"Code{0}"
, i + 1));
}
_ds =
new
DataSet();
_ds.Tables.Add(tbl);
_ds.Tables.Add(tbl2);
this
.radGridView1.DataMember =
"MainTable"
;
this
.radGridView1.DataSource = _ds;
this
.radGridView1.Columns[
"text"
].Width = 150;
this
.radGridView1.Columns[
"value"
].Width = 150;
//GridViewTextBoxColumn col = new GridViewTextBoxColumn();
//col.HeaderText = "CustomColumn";
//col.UniqueName = "CustomColumn";
//col.Width = 150;
//this.radGridView1.Columns.Add(col);
}
I'm just setting some values here, and in the previous method i have changed the ValueMember for the DropDown.
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga

In case others run into this problem, it turned out that the combobox was bound to a list of numbers. But the row data stored the number in a string. So that is why it was not matching up the row's value in the combobox.
I converted the list of numbers to a list of strings and then was able to make this work.
Since your code confirmed that this should work, I then focused on how my code was different and was able to find the problem.
Thanks again!

I'm glad i was able to help, if you have any more questions please just let me know,
Best Regards,
Emanuel Varga

Hello!
How can I determine the grid view instance firing the EditorRequired and CellBeginEdit events from those event handlers? I cannot use explicit form field like "this.radGridView1", because I have a dynamic (data-driven) number of grid views. At least, I need to access the current row info.
Thank you.

So something like this:
var currentGrid = sender as radGridView;
Hope this helps.

Unfortunately, the sender in both these event handlers is GridViewEditManager, not RadGridView.

Sadly, there is no clean way of doing this, but you can get the grid that is in edit mode and that has the EditorManager == sender, like so:
void
radGridView1_CellBeginEdit(
object
sender, GridViewCellCancelEventArgs e)
{
if
(radGridView1.IsInEditMode && radGridView1.EditorManager == sender)
{
}
}
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga


I am using Silverlight radgridview and I need the exact same functionality in my application. Do you have a sample avaialble for Silverlight?
Thanks in advance.
Subha

Didn't have the opportunity yet to play with the silverlight controls, but you could ask someone on the silverlight forums, they should be able to offer you a solution.
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga
Telerik WinForms MVP

I can see Items if I click dropdownlist. But when I click other cell (for example datetime cell) , I can see index number for selected item in dropdownlist. How can I see selected item?
Thank you in advance for your help
Kerim
Could you please share a sample code snippet that demonstrates how you initialize the grid and its columns?
All the best,Svett
the Telerik team

I solved my problem.