Modify a single column in a datagrid?

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
 
C

Chris, Master of All Things Insignificant

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
 
C

Chris, Master of All Things Insignificant

*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
 
B

Bruce D

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
 
C

Chris, Master of All Things Insignificant

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
 

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