Using GridViewComboBox Column want to show placeholder text.

1 Answer 49 Views
GridView
Shubham
Top achievements
Rank 2
Iron
Iron
Iron
Shubham asked on 18 Jul 2023, 10:01 AM

I want to show placeholder text in GridViewComboBox column.

below Select... and All is placeholder. How I can do this with GridViewComboBox Column.

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Jul 2023, 05:40 AM

Hello, Shubham,

RadGridView offers the CellEditorInitialized event which is suitable to adjust the editor after it is initialized and set the initial text: 

        private void RadGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
        {
            RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
            if (editor!=null)
            {
                RadDropDownListEditorElement el = editor.EditorElement as RadDropDownListEditorElement;
                if (editor.Value == null || editor.Value.ToString() == string.Empty)
                {
                    el.ForeColor = Color.Gray;
                    el.Text = "Enter your name";
                }
                else
                {
                    el.ForeColor = Color.Black;
                }               
            }
        }

I hope this information helps. If you need any further assistance please don't hesitate to contact me.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Shubham
Top achievements
Rank 2
Iron
Iron
Iron
commented on 24 Jul 2023, 05:03 AM

Hi Dess,

The problem with above code is that it will appear when user click on cell.
I just wanted to appear once the grid is displayed or user adds up row.

Thankyou for the response.

Regards,
Shubham Jain

Todor
Telerik team
commented on 25 Jul 2023, 12:17 PM

Hello, 

The previous reply from Dess is affecting the edit mode of the RadGridView control. If you want to add the placeholder text when the grid is not in edit mode, you can use the CellFormatting event and set the customize the cell text if the value has not been set:

private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement.ColumnInfo.Name == "LastName" && e.CellElement.Value == null)
    {
        e.CellElement.Text = "Enter your name";
    }
}

If you need any further assistance please don't hesitate to contact me. 

Shubham
Top achievements
Rank 2
Iron
Iron
Iron
commented on 26 Jul 2023, 06:28 AM

Hi Todor,

It worked for me. I accept your answer


Thankyou for your advice.


Regards,
Shubham Jain

 

Tags
GridView
Asked by
Shubham
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or