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

Formatting numbers in List of GridViewComboBoxColumn

2 Answers 87 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andreas
Top achievements
Rank 1
Andreas asked on 28 Apr 2017, 08:30 AM

Hi, 

I want to format the numbers of a list in a GridViewComboBoxColumn. The selected value is formatted correctly (Formatstring of the column is set to {0:N0}). But when the filter dialog is opened, the possible values are not formatted (no thousand seperators, 4 digits). How can I format these values? 

Thanks in advance, 

Andreas

2 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 28 Apr 2017, 11:12 AM
Hello Andreas, 

Thank you for writing.  

In order to format the nodes in the Excel-Like filter popup, it is necessary to handle the RadListFilterPopup.MenuTreeElement.TreeView.NodeFormatting event. Here is demonstrated a sample code snippet which result is illustrated in the attached screenshot:
public RadForm1()
{
    InitializeComponent();
 
    this.radGridView1.DataSource = this.categoriesBindingSource;
 
    GridViewComboBoxColumn comboCol = new GridViewComboBoxColumn("ComboCol");
    comboCol.DataSource = this.productsBindingSource;
    comboCol.DataType = typeof(int);
    comboCol.FormatString = "{0:N3}";
    comboCol.ValueMember = "ProductID";
    comboCol.DisplayMember = "ProductID";
    this.radGridView1.Columns.Add(comboCol);
 
    this.radGridView1.EnableFiltering = true;
    this.radGridView1.ShowHeaderCellButtons = true;
    this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
 
    this.radGridView1.FilterPopupInitialized += radGridView1_FilterPopupInitialized;
}
 
private void radGridView1_FilterPopupInitialized(object sender, FilterPopupInitializedEventArgs e)
{
    RadListFilterPopup popup = e.FilterPopup as RadListFilterPopup;
    if (popup != null)
    {
        popup.MenuTreeElement.TreeView.NodeFormatting -= TreeView_NodeFormatting;
        popup.MenuTreeElement.TreeView.NodeFormatting += TreeView_NodeFormatting;
    }
}
 
int id = -1;
 
private void TreeView_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
{
    if (e.Node.Level == 1 && int.TryParse(e.NodeElement.ContentElement.Text, out id))
    {
        e.NodeElement.ContentElement.Text = string.Format("{0:N3}", id);
    }
}
 
private void RadForm1_Load(object sender, EventArgs e)
{
    this.productsTableAdapter.Fill(this.nwindDataSet.Products);
    this.categoriesTableAdapter.Fill(this.nwindDataSet.Categories);
     
    foreach (GridViewDataRowInfo row in this.radGridView1.Rows)
    {
        row.Cells["ComboCol"].Value = 1;
    }
}

If it is not the exact requirements please specify in details what is the exact goal that you are trying to achieve. Thus, we would be able to assist you further. Thank you in advance.

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Andreas
Top achievements
Rank 1
answered on 28 Apr 2017, 11:53 AM

Hello Dess, 

it was the hint I needed, and it works fine. The filter options are now formatted correctly.

Thanks a lot, 

Regards,

Andreas

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