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

FormatString + Colums Pin problem in the Radgridview

4 Answers 176 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ludovic
Top achievements
Rank 2
Ludovic asked on 19 Jan 2012, 05:24 AM
Hello everyone,

I am new to Telerik and I am trying to show some reports in a RadGridview but some data doesn't show correctly. I have currenlty 2 problems.

Format String
I tried different ways to set up the FormatString. It doesn't change the format in the cells. (see screenshot1).
I want the numbers to look like 999,999,999,999.99 or 99.00 or 0.00 for example and the date to look like 03/02/2010 or 12/24/2001 but it doesn't want to change. When I sent the data to the radgridview, it is send as a string.
I tried different things to format the numbers and the date:
radGridViewSaleReport.Columns["Date1"].FormatString = "{0:MM/dd/yyyy}";
 
radGridViewSaleReport.Columns["Amount1"].FormatString = "{0:#,###0.00;(#,###0.00);0.00}";
radGridViewSaleReport.Columns["Amount2"].FormatString = "{0:#,0.00}";
radGridViewSaleReport.Columns["Amount4"].FormatString = "${0:F2}";
radGridViewSaleReport.Columns["Price/Sq.M."].FormatString = "{0:C}";
radGridViewSaleReport.Columns["Selling Price"].FormatString = "{0:###,###,###,##0.00}";
radGridViewSaleReport.Columns["TotalInstPaid"].FormatString = "{0: ####.## THB}";

What ever I try, it doesn't change any format of the numbers. Do you know why? I tried to put the Formatting code before or after setting the view, it has no effect.

Pin Columns.
I want to pinned the first 2 columns of my radgridview. No problem to do that. It's well explained in the documentation but the result is scary. I follow the documentation and just wrote this after setting up the view (if I put it before setting up the view, it doesn't work). I started first with 1 column:
radGridViewSaleReport.Columns["Customer Name"].IsPinned = true;
Some empty space appears after the columns (see screenshot1) and I can not scrool horizontally more than this and 2 columns or more are hidden (see screenshot2).
Do you have any idea why this happen?
When I do it for 2 columns (see screenshot3), the empty space become even bigger.
Do you know anyway to have this to show correclty?

Thanks,
LB

4 Answers, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 23 Jan 2012, 04:34 PM
Hi Ludovic,

Thank you for contacting us. I am getting straight to your questions:

1. Most probably the StringFormat does not apply correctly in this case, because your columns are of type GridViewTextBoxColumn. You have to use GridViewDateTimeColumn for date types and GridViewDecimalColumn for numeric types. These columns will be automatically generated when the AutoGenerateColumns property is set to true:

this.radGridView1.AutoGenerateColumns = true;

Of course, all underlying data should be also strongly typed.

2. When using column groups view, you should not set the PinPosition property for columns. Instead, you should set the same property in the column group at the root level that contains the column. For example:

ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();
//...
view.ColumnGroups[1].PinPosition = PinnedColumnPosition.Left;

I hope this helps. If you need further assistance, I will be glad to help.

Regards,
Jack
the Telerik team

SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

0
Ludovic
Top achievements
Rank 2
answered on 24 Jan 2012, 05:14 AM
Dear Jack,

Thank you for your answer. It works perfectly for the pin column. It makes something very nice and smooth.

I also followed your advices and changed the column types to Decimal and DateTime according to the type of data. It works much better. I still have a question about this which I can't resolve by myself.

I still have problem formating the numbers, through the result is almost good now. For example I got the number formatted this way : 2,987,843,00 instead of 2,987,843.00. I set all the decimal columns the same way as below:

GridViewDecimalColumn decimalColumn6 = new GridViewDecimalColumn();
                decimalColumn6.Name = "Amount2";
                decimalColumn6.HeaderText = "Amount";
                decimalColumn6.FormatString = "{0:#,0.00}";
                radGridViewSaleReport.Columns.Add(decimalColumn6);

with the FormatString = "{0:#,0.00}", but the program still doesn't want to use the dot before the decimals but the comma.
 All the data are parsed from a string array into double. I tried to parse the numbers into decimal instead, I got the same wrong formating with the comma.

For the date, the Format string works perfectly and give the expected result.

Any idea to change the formatting of the numbers?

Thank you.

Best regards,
Ludovic
0
Ludovic
Top achievements
Rank 2
answered on 24 Jan 2012, 06:40 AM
Hello again! :)


After trying different formats, I found finally what I wanted! The numbers are displayed correctly! Here is the code below to make the numbers display as such:  2,987,843.00.


GridViewDecimalColumn decimalColumn12 = new GridViewDecimalColumn();
decimalColumn12.Name = "Amount4";
decimalColumn12.HeaderText = "Amount";
decimalColumn12.FormatString = "{0:#,0.00}";
decimalColumn12.DataType = typeof(decimal);
decimalColumn12.FormatInfo = new System.Globalization.CultureInfo("th-TH");
radGridViewSaleReport.Columns.Add(decimalColumn12);

I tried to put the FormatString="{0:C}" but the Baht symbol (B) was displayed before the number and according to my Thai colleagues it should be displayed after. So I just removed the symbol which I do not have to display anyway.

Thanks for your help and your directions, Jack! :)
I am happy to be done with that sale report in the radgridview. I think now I understand more how it works. I think I will be able to do the other reports without asking so many questions... 

Best regards,
Ludovic
0
Jack
Telerik team
answered on 26 Jan 2012, 04:46 PM
Hi Ludovic,

I am glad to hear that you have found a solution for this issue. Please do not hesitate to contact us if you have further questions.
 
Kind regards,
Jack
the Telerik team

SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

Tags
GridView
Asked by
Ludovic
Top achievements
Rank 2
Answers by
Jack
Telerik team
Ludovic
Top achievements
Rank 2
Share this question
or