0

I'm pretty new to WPF, so pardon my ignorance. I currently have a List of objects that I am using as an ItemsSource for a DataGrid. One of the fields of the objects is a float data type, and of course displays decimal places on the DataGrid when used as an ItemsSource.

I would like to remove these decimal places, without changing the underlying data, if that's possible. In other words, I would like to display them as if they were ints on the DataGrid, but leave them as floats in the List.

If this is possible using C#, that would be super-great-nifty. XAML makes me want to vomit :)

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Tevis
  • 729
  • 1
  • 12
  • 27
  • 3
    `XAML makes me want to vomit` - Then go back to winforms. WPF is not for newbies =) – Federico Berasategui Apr 26 '13 at 18:31
  • So you prefer coding in a big long string (tag) as opposed to nice clean-cut object notation? To each their own I suppose :) – Tevis Apr 26 '13 at 18:59
  • XAML is not coding. XAML is to define the UI. and of course I prefer XAML to the multiple horrible hacks you need to do anything in other technologies (P/Invoke? Owner Draw? WTF is that??) – Federico Berasategui Apr 26 '13 at 19:15
  • Semantics won't save you from the fact that tags are ugly! – Tevis Apr 26 '13 at 19:16
  • again, if you don't like it, go back to your winforms' drag and drop + horrible hack stuff. Nobody forces you to WPF. You can keep making applications that look like windows 95 if you want. – Federico Berasategui Apr 26 '13 at 19:18
  • By the way, I don't need to be "saved" from anything. I'm not the one arguing in favor of a dinosaur, dead and completely useless technology and mentality. – Federico Berasategui Apr 26 '13 at 19:22
  • I never argued for winforms bro, just saying tags are ugly – Tevis Apr 26 '13 at 19:44
  • 1
    Agreed. It would be fantastic if XAML was some form of JSON instead, still 12390812038347297 times better than anything else current in existence. – Federico Berasategui Apr 26 '13 at 19:46

1 Answers1

2

If you're simply trying to format the value for display purposes, you can use the StringFormat property of the Binding like this:

<DataGridTextColumn Header="My Number" Binding="{Binding MyNumber, StringFormat=N}"/>

This prevents the need for a Converter in very simple cases. If you need more power/flexibility, then a Converter is definitely the way to go.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Brian S
  • 5,675
  • 1
  • 22
  • 22