2

I am new in Linq. I have following query:

var BeachDetail = (from Personal in dc.t_return_to_beaches
                   where Personal.emo_number == EmoNumber
                   select Personal).ToList();

 Grd_ReturnToBeach.ItemsSource = CurrentController.GetItemSource(BeachDetail)

Here i am using DevExpress Grid to bind.

<dxg:GridControl x:Name="Grd_ReturnToBeach" MinHeight="70">
</dxg:GridControl>

which retrieves more than 16 columns.

It works fine for me but there are two columns named

  weight (numeric(15, 4))

and

   value (numeric(15, 4))

Problem :

if I enter 12 and 13.45 in these columns then i got 12.0000 and 13.4500.But i want to show in the grid exact value which i entered earlier like 12 and 13.45.

Sunny
  • 3,185
  • 8
  • 34
  • 66
  • This is not a linq issue, but formatting the grid. Which grid are you using? – Amiram Korach Nov 06 '12 at 09:45
  • It sounds like you only need to specify a display format for whatever grid you have. Can you please include the details on what platform and/or control you're using? – moribvndvs Nov 06 '12 at 09:45

2 Answers2

1

You should format your grid according to your requirement. But if you want to get the results as formatted in the grid then I believe you have to create anonymous type in your select statement, specify all the columns and the one you want to format and then bind the list of anonymous type to the grid.

May be something like:

var BeachDetail =  from Personal in dc.t_return_to_beaches
                   where Personal.emo_number == EmoNumber
                   select new 
                       {
                         Col1 = personal.Col1,
                         Col2 = personal.Col2,
                         Col3 = personal.Col3,                         
                         ....................
                         ....................
                         weight = String.Format("{0:0.00}", personal.Weight),
                         value = String.Format("{0:0.00}", personal.Value),
                       };

The problem with the above approach is that you loose your object type and weight and values are of type string in the Grid, so if you try to get these values back and perform some operations then it might cause you problems.

moribvndvs
  • 42,191
  • 11
  • 135
  • 149
Habib
  • 219,104
  • 29
  • 407
  • 436
0

Use tostring and a format specifier like G

MSDN

I think I have a SO ref here somewhere

Community
  • 1
  • 1
PaulMolloy
  • 612
  • 6
  • 13