I have a custom grid control and I'm stuck on an issue in the data binding.

Using a method similar to the DataGridColumnStyles class, I have a column
style class that allows you to map the bound datasource fields to the grid
columns.

I've added a Format property which will take a format string such as "{0:C}"
which will then convert the underlying data to a currency string.

This works very nicely. The problem is when the user goes in and edits data.
Let's say that a column has the above currency format string and the data in
the cell is $4.45

If the user changes the value, I need to then update the data source. I need
to handle the situation where the user puts in either $4.50 or 4.50 and be
able to properly convert it back to the underlying type.

Is there an easy way to do this without doing a huge case statement for all
the different data types?

The underlying data can, of course, be of any type. In the grid it's
represented as a string. All I have is the format string to know about
formatting. I'd rather not have to parse the format string to figure out how
to parse the underlying data. Is there some way I can use it to do the
parsing?

Thanks.

Pete

Re: Data Conversion in a grid by ClayB

ClayB
Tue Jun 22 05:45:08 CDT 2004

Maybe the information in this MS KB will be helpful to you.

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q318581

============================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

<pdavis68@hotmail.com> wrote in message
news:x7ednfxND_Xr90rdRVn-hA@giganews.com...
> I have a custom grid control and I'm stuck on an issue in the data
binding.
>
> Using a method similar to the DataGridColumnStyles class, I have a column
> style class that allows you to map the bound datasource fields to the grid
> columns.
>
> I've added a Format property which will take a format string such as
"{0:C}"
> which will then convert the underlying data to a currency string.
>
> This works very nicely. The problem is when the user goes in and edits
data.
> Let's say that a column has the above currency format string and the data
in
> the cell is $4.45
>
> If the user changes the value, I need to then update the data source. I
need
> to handle the situation where the user puts in either $4.50 or 4.50 and be
> able to properly convert it back to the underlying type.
>
> Is there an easy way to do this without doing a huge case statement for
all
> the different data types?
>
> The underlying data can, of course, be of any type. In the grid it's
> represented as a string. All I have is the format string to know about
> formatting. I'd rather not have to parse the format string to figure out
how
> to parse the underlying data. Is there some way I can use it to do the
> parsing?
>
> Thanks.
>
> Pete
>
>
>



Re: Data Conversion in a grid by pdavis68

pdavis68
Tue Jun 22 11:30:33 CDT 2004

Actually, my needs are a little more complex than what that article
provides, but thanks.

I came up with a method that seems to be working pretty well. It required
distinguishing among only 3 data types and the rest are all handled in a
generic fashion by calling the Parse() method against the type using
reflection. This appears to work quite well. How did I ever live without
reflection???

Pete

"ClayB [Syncfusion]" <clayb@syncfusion.com> wrote in message
news:eZ7SNYEWEHA.3492@TK2MSFTNGP10.phx.gbl...
> Maybe the information in this MS KB will be helpful to you.
>
> http://support.microsoft.com/default.aspx?scid=kb;en-us;Q318581
>
> ============================
> Clay Burch, .NET MVP
>
> Visit www.syncfusion.com for the coolest tools
>
> <pdavis68@hotmail.com> wrote in message
> news:x7ednfxND_Xr90rdRVn-hA@giganews.com...
> > I have a custom grid control and I'm stuck on an issue in the data
> binding.
> >
> > Using a method similar to the DataGridColumnStyles class, I have a
column
> > style class that allows you to map the bound datasource fields to the
grid
> > columns.
> >
> > I've added a Format property which will take a format string such as
> "{0:C}"
> > which will then convert the underlying data to a currency string.
> >
> > This works very nicely. The problem is when the user goes in and edits
> data.
> > Let's say that a column has the above currency format string and the
data
> in
> > the cell is $4.45
> >
> > If the user changes the value, I need to then update the data source. I
> need
> > to handle the situation where the user puts in either $4.50 or 4.50 and
be
> > able to properly convert it back to the underlying type.
> >
> > Is there an easy way to do this without doing a huge case statement for
> all
> > the different data types?
> >
> > The underlying data can, of course, be of any type. In the grid it's
> > represented as a string. All I have is the format string to know about
> > formatting. I'd rather not have to parse the format string to figure out
> how
> > to parse the underlying data. Is there some way I can use it to do the
> > parsing?
> >
> > Thanks.
> >
> > Pete
> >
> >
> >
>
>