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

ComboBox, TextBox and Label in the Same GridViewCell

3 Answers 132 Views
GridView
This is a migrated thread and some comments may be shown as answers.
kotu k
Top achievements
Rank 1
kotu k asked on 23 Jul 2010, 06:21 AM
Hi
    M new for Teleric for Working Windows.
I am facing some Issues with the Custome control which having ComboBox, TextBox and Label. My Requirement is bellow:

1.In GridView one Column having ComboBox, TextBox and Label.
2.Dynamically we pass Data to ComboBox usinf DataSource.
3.Based on the Value in the ComboBox, TextBox and Label will be Hidden Or Visable for Corresponding Row.

And How to Bind the Class with these ComboBox and TextBoxs.

Please help me.

Thanks,
KKC

3 Answers, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 29 Jul 2010, 10:01 AM
Hi kotu k,

You can easily achieve that by subscribing to ValueChanged event and CellFormatting event. You can use the following code snippet:
private void radGridView2_ValueChanged(object sender, EventArgs e)
{
    RadComboBoxEditor comboBoxEditor = sender as RadComboBoxEditor;
 
    if (comboBoxEditor != null)
    {
        this.radGridView2.CurrentRow.InvalidateRow();
    }
}
 
private void radGridView2_CellFormatting(object sender, CellFormattingEventArgs e)
{
    GridCellElement cellElement = e.CellElement;
 
    if (!(cellElement.RowInfo is GridViewDataRowInfo))
    {
        return;
    }
 
 
    if (cellElement.ColumnInfo.Name == "Name" ||
        cellElement.ColumnInfo.Name == "HireDate")
    {
        RadComboBoxEditor comboBoxEditor = this.radGridView2.ActiveEditor as RadComboBoxEditor;
 
        object value = null;
 
        if (comboBoxEditor != null)
        {
            value = comboBoxEditor.Value;
        }
        else
        {
            value = e.CellElement.RowInfo.Cells["ComboBox"].Value;
        }
 
        // Your condition should be here
        if (Convert.ToString(value).Contains("2"))
        {
            e.CellElement.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
        }
        else
        {
            e.CellElement.ResetValue(LightVisualElement.VisibilityProperty, Telerik.WinControls.ValueResetFlags.Local);
        }
 
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.VisibilityProperty, Telerik.WinControls.ValueResetFlags.Local);
    }
}

In ValueChanged event we invoke InvalidateRow method, which force CellFormatting event to be processed. You can read more about it in this documentation article.

Notice that the supplied code snippet works in the latest version Q2 2010 (v2010.2.10.713).

All the best,
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
0
kotu k
Top achievements
Rank 1
answered on 29 Jul 2010, 02:19 PM
Hi Svett,
    Thank you for your response. And also i need how to bind the Business Entities with the different controls with the Same cell of GridView.

Thanks,
KKC
0
Svett
Telerik team
answered on 03 Aug 2010, 10:15 PM
Hi kotu k,

Could you give me more information about your scenario? What exactly are your requirements? The GridCellElement instances are virtualized and reused each time when you scroll down the grid. Hence, you cannot directly bind another components to the cell element. Probably, you want to do it for its data source. RadGridView does not restricts the possibility to achieve that.

Sincerely yours,
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
kotu k
Top achievements
Rank 1
Answers by
Svett
Telerik team
kotu k
Top achievements
Rank 1
Share this question
or