Modify a single column in a datagrid?

  • Thread starter Thread starter Bruce D
  • Start date Start date
B

Bruce D

Is there a way to programatically set the format of just one column in a
datagrid? I have a datagrid bined to a datasource. My dataview has 6
columns. And I want to format one column ('amount')...without have to mess
with all the other columns.
If I use DataGridTableStyle() and DataGridTextBoxColumn() (see following
code)...my datagrid only displays 1 column!

Dim dvFinders As New DataView(dtFinders)
DataGrid1.DataSource = dvFinders
' set properties
Dim x As New DataGridTableStyle
x.MappingName = "Finders"
Dim z As New DataGridTextBoxColumn
z.MappingName = "lastname"
z.Width = 150
x.GridColumnStyles.Add(z)
DataGrid1.TableStyles.Add(x)

This datagrid is making my project a lot harder than it should be!

Any help is appreciated!
-bruce duncan
 
If you are going to use DataTable for one column, you'll need to add one for
each column you want to display. If you don't want to add a tablestyle for
each column, then add a column to your datatable (dataview has a datatable)
and for the column directly on the datatable.

Chris
 
*Corrected wording

If you are going to use DataGridTableStyle for one column, you'll need to
add one for each column you want to display. If you don't want to add a
DataGridTableStyle for each column, then add a column to your datatable
(dataview has a datatable) and for the column directly on the datatable.

Chris
 
Thanks Chris!
How about another question? I have a DataTable that has both lastname,
firstname as seperate fields. How can I display them as one field in the
datagrid (and yes...I was forced to use DataGridTableStyle for each column)?

TIA
-bruce
 
I assume you are getting your data out of a database? In that case I would
do it in your select statement.

Select FirstName + ' ' + LastName as Name, TableName.* from TableName

There may be a nice slick way of doing it client side, but this is how I've
always done stuff like that.
Chris
 
Back
Top