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

Define different column types in single column

4 Answers 206 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Harry
Top achievements
Rank 1
Harry asked on 29 Sep 2010, 08:42 PM
Is it possible to define different GridView column type based on column value at row loading event at runtime?
I like to be able to define calendar, combo, or text in the same column.

For example, I have following records:
Col1        Col2            Col3
Daily        10/1/2010    Check my email
Weekly    Monday        Check to see if weekly backup worked
Monthly    1                  Check to see if monthly order came thru

I like to be able to change cell column type on Col2 based on value in Col1.
So, in this case,
Col2 on the 1st row has GridViewDataTimeColumn where a user can select date from calendar. 
Col2 on the 2nd row has combo box with monday, tuesday, wednesday, etc...
Col3 on the 3rd row has free text where a user can enter numerical number 1 thru 31

So, Col1 is defined as combo box with Daily, Weekly, Monthly, etc...

Is this possible to do this using your radgridview?

Thanks.

Harry Idachi

4 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 30 Sep 2010, 05:38 AM
Hello Harry,

Sadly i don't think it's possible to accomplish what you are trying to do here, because by construction, a column holds the same type on all rows, but that doesn't mean you cannot create a text column and on validation to do the necessary checks based on RowInfo and the previous cell.

You should take a look at this article about Cell validation

If you have any other questions, please do not hesitate to say so.

Best Regards,
Emanuel Varga
0
Ramius
Top achievements
Rank 1
answered on 30 Sep 2010, 09:49 AM

Hello Harry,

you can do this with the GridView and the EditorRequired Event. 

In the EditorRequired Event you can create the Editor for the cell in Col2 based on the value in Col1. 

Best Regards,

Ramius

0
Sheraz Naseeb
Top achievements
Rank 1
answered on 30 Sep 2010, 11:10 AM
Actually I need some sort of similar functionality, whats happening is I am saving dates in to database as String or Integer, when it comes to the datagrid I use the CellFormatting event to get it into date format.

Now, when I go to the filtering cell it shows a text box for filtering and if it is date column into the database then it shows a DateTimePickerElement into the filtering row.

Is there anyway I can get the RadDateTimePickerElement into the filtering cell when the column data type is string or integer? and also how to get access selected date from that DatePickerElement when it is clicked???

Please help...

Sheraz
0
Svett
Telerik team
answered on 05 Oct 2010, 10:37 AM
Hi Sheraz,

You can use the EditorRequired event where you can replace the default editor for the filter cell. You can read more about it in the online documentation. You can determine the value that the editor should commit to your data source by creating a custom editor:

public class MyDateTimeEditor : RadDateTimeEditor
{
    public override object Value
    {
        get
        {
            GridCellElement cellElement = this.OwnerElement as GridCellElement;
            if (cellElement != null && cellElement.ColumnInfo.Name == "YourStringColumnName")
            {
                RadDateTimePickerElement element = this.EditorElement as RadDateTimePickerElement;
                DateTime value = element.Value;
                return CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(value.Month);
            }
            return base.Value;
        }
        set
        {
            base.Value = value;
        }
    }
}

 


You have to replace the default editor:
private void radGridView1_EditorRequired(object sender, Telerik.WinControls.UI.EditorRequiredEventArgs e)
{
    if (this.radGridView1.CurrentColumn.Name == "ColumnThatShouldHaveDateTimeEditor")
    {
        e.EditorType = typeof(MyDateTimeEditor);
    }
}

I hope this helps.

Kind regards,
Svett
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
Tags
GridView
Asked by
Harry
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Ramius
Top achievements
Rank 1
Sheraz Naseeb
Top achievements
Rank 1
Svett
Telerik team
Share this question
or