2 Replies - 4477 Views - Last Post: 10 September 2012 - 03:01 AM Rate Topic: -----

#1 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 223
  • Joined: 25-April 11

Change Cell-Type in DataGridView

Posted 28 May 2012 - 03:22 AM

Hello everybody

I have a DataGrid that is filled out of Data retrived from a VFP-Database. My issue is that there is a Column with decimal values, that I want to convert to strings in order to write in some text. I have tried to convert te cells or the entire column to string, but it doesnt work as expected.

I have used the following commands (not all together ;) one by one ):
1) dataGrid.Columns["hot_kunde"].CellTemplate.ValueType = typeof(string);
2) dataGrid.Columns["hot_kunde"].ValueType = typeof(string);
3) for (int i = 0; i < dataGrid.RowCount; i++)
   {
       dataGrid.Rows[i].Cells[1].ValueType = typeof(String);
       dataGrid.Rows[i].Cells[1].Value = "test";
   }


If I use a MessageBox to see the new type it shows "System.String", nevertheless all of theese commands throw the same exception saying that a decimal value is expected.

What do I do wrong? Any ideas?

Is This A Good Question/Topic? 0
  • +

Replies To: Change Cell-Type in DataGridView

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3652
  • View blog
  • Posts: 11,421
  • Joined: 05-May 12

Re: Change Cell-Type in DataGridView

Posted 05 June 2012 - 04:01 PM

It's been a while, but I believe the correct technique is to keep the value type as Decimal, but use the FormattedValueType for display. If you need some custom formatting, you use the CellFormatting event: http://msdn.microsof...formatting.aspx

This post has been edited by Skydiver: 05 June 2012 - 04:02 PM

Was This Post Helpful? 1
  • +
  • -

#3 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 223
  • Joined: 25-April 11

Re: Change Cell-Type in DataGridView

Posted 10 September 2012 - 03:01 AM

Thank you for your reply. I understand...

In fact my intention was to change the customers-id's with their names in the same cell, but what I afterwards did, was hiding the id-column and adding a new one with the names of my customers. --> Problem resolved :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1