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

Change TextAlignment of edited GridViewMaskBoxColumn

2 Answers 84 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Timothy
Top achievements
Rank 1
Timothy asked on 05 Jan 2013, 02:05 AM
Please refer to attached images for clarification if needed.

I have a couple of GridViewMaskBoxColumns in child rows of my RadGridView control. I'm setting the TextAlignment of the column to MiddleCenter (see GridViewMaskBoxColumn_1.jpg). This sets the alignment of the displayed value as expected.

However, I would also like data to be centered when editing the data. As GridViewMaskBoxColumn_2.jpg show the data is left aligned.

I've tried to create a custom editor but the examples I've found here are a little over my head, in C# and don't seem to relate to what I'm wanting to do anyway.

Can someone show me how to either get to the property I need to set or else show me how (in VB.NET) to create a custom editor that would do this for me.

Thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Plamen
Telerik team
answered on 09 Jan 2013, 02:31 PM
Hi Timothy,

Thank you for writing.

In order to set the alignment of the text in the editor, you should use the CellEditorInitialized event which is fired after the editor has been internally initialized:
Private Sub RadGridView1_CellEditorInitialized(sender As Object, e As GridViewCellEventArgs)
    Dim editor As RadMaskedEditBoxEditor = TryCast(e.ActiveEditor, RadMaskedEditBoxEditor)
    editor.MaskTextBox.TextAlign = HorizontalAlignment.Center
End Sub

The Horizontal Alignment enumeration values specify how text is aligned in the editor. The default is HorizontalAlignment.Left. Take a look at this article about TextAlign property of the standard TextBox control: http://msdn.microsoft.com/en-us/library/system.windows.forms.textbox.textalign.aspx

Attached you could find a sample project, which demonstrates the desired behavior.

I hope this helps.

Greetings,
Plamen
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
0
Timothy
Top achievements
Rank 1
answered on 09 Jan 2013, 11:16 PM
Thanks so much!
Tags
GridView
Asked by
Timothy
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Timothy
Top achievements
Rank 1
Share this question
or