Change the Column display prior to show the DataGrid

G

Guest

Is there an easy way to change a DataGrid specific column display
to something else then the actual bind data value from the datase
using something like the format or parse ?

What I would like to append before the grid is show, is to make some transformation
from one integer field from the dataset.table to its text equivalent "0 = Sales, 1 = Orders
using a function that could be called prior to show the datagrid.

Right now I did change the dataset by adding a new column with the text equivalen
after the initial load of the dataset, so I have to iterate trough all row and this is an optio
I will like to avoid.

I know I can use this king of code for textbox simple databinding

Binding b
b = txtUnitPrice.DataBindings.Add("Text", vueDetail, "UnitPrice")
b.Format += new ConvertEventHandler(DecimalToCurrencyString)
b.Parse += new ConvertEventHandler(CurrencyStringToDecimal)

Any idea.

Carl,
 
N

Norman Yuan

Although you can derive a custom datagrid column from DataGridTextBoxColumn,
I think simply add a descriptivr text column to the datatable, as you did,
is the simler and easier solution. The next step you did, though, is a bit
out of track. You only need to bind the datatable to the DataGrid with
proper setting of the TableStyle of the datagrid: you o not map a column to
the numeric field in table, instead, map the column to the descriptive text
column you added to the datatable. You can do it in VS.NET's form designer
with just a few mouse clicks and key strokes, no code is necessary.
 
G

Guest

Hi Norman

I actually create the datagrid trough code and table style, however I wa
trying to avoid to iterate trough the Dataset,table rows to transform the integer
field to its text equivalent in the new field. Some tables will grow trough tim
and I was expecting that .NET could provide something like parse and forma
before the column is actually display for the datagrid

It works for now, but I am pretty sure there is something better that I can do

If someone else have an other idea please let me know

Thanks for your time

Car


----- Norman Yuan wrote: ----

Although you can derive a custom datagrid column from DataGridTextBoxColumn
I think simply add a descriptivr text column to the datatable, as you did
is the simler and easier solution. The next step you did, though, is a bi
out of track. You only need to bind the datatable to the DataGrid wit
proper setting of the TableStyle of the datagrid: you o not map a column t
the numeric field in table, instead, map the column to the descriptive tex
column you added to the datatable. You can do it in VS.NET's form designe
with just a few mouse clicks and key strokes, no code is necessary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top