8 Answers, 1 is accepted
Hi, Hengky,
In case you don't want to use a GridViewMaskBoxColumn , please have in mind that RadGridView offers the CellFormatting event which gives you the possibility to display any text in the cell by setting the CellElement.Text property to the desired text.
Thus, considering the cell's Value, you can format the CellElement.Text according to your needs.
I hope this information helps.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hi.. Dess sorry for late post ...
I tried to create form Template ...
with grid inside in the form ...
i have made setting for grid ...
like this ...
If HColumnsFormat.Count > 0 Then
For i = 0 To HColumnsFormat.Count - 1
Try
If String.IsNullOrEmpty(HColumnsFormat(i)) Then
Continue For
End If
GridList.Columns(i).FormatString = HColumnsFormat(i)
Catch ex As Exception
End Try
Next
End If
this code is for format the column .... like {0:#,##0}, now i need to make one column {####-##.##} formated
how to make this ...
TQ
Hello, Hengky,
You can set any custom formatted text that you want to the Text property of the CellElement in CellFormatting event. For more information about formatting text please refer to the following MSDN articles:
https://docs.microsoft.com/en-us/dotnet/api/system.string.format?view=netcore-3.1
https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings?redirectedfrom=MSDN#the--custom-specifier-1
https://docs.microsoft.com/en-us/dotnet/api/system.string.substring?view=netcore-3.1
Here is a sample demonstration:
private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
if (e.CellElement.RowIndex > -1)
{
if (e.CellElement.ColumnIndex == 0)
{
e.CellElement.Text = string.Format("{0:##-##.00}", (double)e.CellElement.Value);
}
else
{
e.CellElement.ResetValue(LightVisualElement.TextProperty, ValueResetFlags.Local);
}
}
}
I hope this helps. Should you need further assistance do not hesitate to ask.
Regards,
Nadya
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).
Hello nad...
How to cast maskedbox in child ... ? with format ####-##.##
Dim firstChildtemplate As New GridViewTemplate()
firstChildtemplate.DataSource = (ds.Tables("Detail"))
firstChildtemplate.AllowEditRow = False
firstChildtemplate.AllowAddNewRow = False
.MasterTemplate.Templates.Add(firstChildtemplate)
With firstChildtemplate
.BestFitColumns(BestFitColumnMode.AllCells)
.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill
DirectCast(.Columns("KodeRekening"), GridViewMaskBoxColumn).Mask = "{####-##.##}"
.Columns("KodeRekening").HeaderText = "REKENING"
.Columns("KodeRekening").Width = 100
.Columns("KodeRekening").AllowResize = False
.Columns("KodeRekening").TextAlignment = ContentAlignment.MiddleCenter
End With
thanks before
Hello, Hengky,
The MasterTemplate.Templates collection gives you access to the child templates in RadGridView. Once you get the child GridViewTemplate, its Columns collection returns the columns you see in the child level. Casting the GridViewMaskBoxColumn seems to be correct in the provided code snippet. Thus, you can set the Mask and MaskType for the column: https://docs.telerik.com/devtools/winforms/controls/gridview/columns/column-types/gridviewmaskboxcolumnThe CellFormatting event can also be used for the hierarchical cells as well as it is demonstrated in Nadya's reply. The CellFormattingEventArgs.Row.HierarchyLevel property indicates to which hierarchical level the cell/row belongs.
In case you are still experiencing any further difficulties, feel free to submit a support ticket from your Telerik account and provide a sample project demonstrating the problem you are facing. Thus, we would get better understanding of the precise case and think about a suitable solution. Thank you in advance for your cooperation.
Should you have further questions please let me know.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Hai dess
I just need to cast gridview to maskbox
It's working well if i made to parent grid.
But i dont know how to cast in grid child...
Hai Dess ... How r u ?
Hopely everything fine ... in this covid pandemi ...
Dess... can we just like this code ... for maskedbox ?
DirectCast(.Columns("Tgl"), GridViewDateTimeColumn).FormatString = "{0:dd/MM/yyyy}"
if i just replace to .... , GridViewMaskedColun ... it;s getting error .
Thanks Des...
Hello, Hengky,
If the column doesn't cast to GridViewMaskBoxColumn successfully, this means that it is most probably of another type, e.g. GridViewDecimalColumn. Please make sure that the column is the expected type before converting it to GridViewMaskBoxColumn. Otherwise, you can remove the already existing column and add a new one as below:
Me.RadGridView1.MasterTemplate.Templates(0).Columns.Remove("UnitPrice")
Dim maskBoxColumn As New GridViewMaskBoxColumn()
maskBoxColumn.FieldName = "UnitPrice"
maskBoxColumn.MaskType = MaskType.Numeric
maskBoxColumn.Mask = "C"
maskBoxColumn.FormatString = "{0:C}"
maskBoxColumn.DataType = GetType(Decimal)
Me.RadGridView1.MasterTemplate.Templates(0).Columns.Add(maskBoxColumn)
I have attached my sample project for your reference.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.