This is a migrated thread and some comments may be shown as answers.

One column with multiple edit controls?

25 Answers 469 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rod Hancock
Top achievements
Rank 1
Rod Hancock asked on 25 May 2010, 08:31 PM
I have a GridView containing two visible columns, PropertyName and Value.  The PropertyName is read only, but the value is to be edited.  Most of the time, a text box is reaquired for freeform text, however, sometimes the property has fixed values, which we want to display as a dropdown, or the value may contain a more complex type (xml) which we would like to display a button, and have the button pop up a new gridview with the xml bound to it,

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

Sort by
0
Rod Hancock
Top achievements
Rank 1
answered on 27 May 2010, 03:33 PM
Nobody knows how to do this?

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

0
Rod Hancock
Top achievements
Rank 1
answered on 27 May 2010, 07:49 PM
I've gotten a little further now...   I was using an older version of RadControls for Winform, so I just installed the latest version and write a small test program. I am now able to replace the textbox with an editor, however, it is empty.... it does not contain the value which was displayed in the textbox normally.

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' 

0
Martin Vasilev
Telerik team
answered on 28 May 2010, 02:16 PM
Hello Rod Hancock,

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.
0
Rod Hancock
Top achievements
Rank 1
answered on 28 May 2010, 03:17 PM
Thank you very much.... It works now.
0
Harry
Top achievements
Rank 1
answered on 05 Oct 2010, 01:13 AM
Hi Martin,
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

0
Martin Vasilev
Telerik team
answered on 08 Oct 2010, 11:21 AM
Hi Harry,

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
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
0
Deborah
Top achievements
Rank 1
answered on 08 Oct 2010, 09:52 PM
Both Harry and I have tried your example solution "as is" with no changes.

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?
0
Emanuel Varga
Top achievements
Rank 1
answered on 09 Oct 2010, 12:01 AM
Hello guys,

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
0
Harry
Top achievements
Rank 1
answered on 09 Oct 2010, 03:35 AM
Thanks much for this fix.

It works now!

Harry
0
Deborah
Top achievements
Rank 1
answered on 13 Oct 2010, 11:35 PM
Harry and I now have this in and working. The only problem we still have is with the default.

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!
0
Emanuel Varga
Top achievements
Rank 1
answered on 14 Oct 2010, 07:21 AM
Hello Deborah,

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
0
Deborah
Top achievements
Rank 1
answered on 14 Oct 2010, 04:17 PM
Hi Emanuel -

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?
0
Emanuel Varga
Top achievements
Rank 1
answered on 14 Oct 2010, 04:40 PM
Hello Deborah,

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
0
Deborah
Top achievements
Rank 1
answered on 15 Oct 2010, 04:53 PM
Thank you for your continued help with this. I was doing something similar.

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!
0
Emanuel Varga
Top achievements
Rank 1
answered on 15 Oct 2010, 05:04 PM
Hello again Deborah,

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

Best Regards,
Emanuel Varga
0
George Saveliev
Top achievements
Rank 1
answered on 08 Nov 2010, 07:41 PM

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.

0
Deborah
Top achievements
Rank 1
answered on 08 Nov 2010, 08:03 PM
The Sender parameter tells you the grid that generated the event.

So something like this:

var currentGrid = sender as radGridView;

Hope this helps.
0
George Saveliev
Top achievements
Rank 1
answered on 08 Nov 2010, 08:26 PM

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

0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 08 Nov 2010, 09:53 PM
Hello George,

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)
    {
 
    }
}
And that is the sender grid.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
George Saveliev
Top achievements
Rank 1
answered on 10 Nov 2010, 07:56 AM
This works for me. Thank you!
0
Subha
Top achievements
Rank 1
answered on 09 Dec 2010, 06:11 PM
Hi,

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
0
Emanuel Varga
Top achievements
Rank 1
answered on 09 Dec 2010, 09:12 PM
Hello 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
0
Bimar
Top achievements
Rank 1
answered on 17 Feb 2011, 11:19 AM
Hello,

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
0
Svett
Telerik team
answered on 22 Feb 2011, 03:40 PM
Hello Volkan,

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
0
Bimar
Top achievements
Rank 1
answered on 25 Feb 2011, 03:04 PM
Thanks :)

I solved my problem.

Tags
GridView
Asked by
Rod Hancock
Top achievements
Rank 1
Answers by
Rod Hancock
Top achievements
Rank 1
Martin Vasilev
Telerik team
Harry
Top achievements
Rank 1
Deborah
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
George Saveliev
Top achievements
Rank 1
Subha
Top achievements
Rank 1
Bimar
Top achievements
Rank 1
Svett
Telerik team
Share this question
or