Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding unbound column to a grid

Status
Not open for further replies.

shangrilla

Programmer
Nov 21, 2001
360
0
0
US
Hi All:

I have a dataGrid(bound to a datatable). After the grid is loaded I add an unbound column to the grid. This new column is the last column(right most) in the grid.

I want this new column to be the left most column when the grid is displayed. How can I do that?

Thanks.
 
You can create a tablestyle and add the columns to it in the order you want them to show up.


example

Me.datagrid1.TableStyles.Clear()
Dim TableStyle As New DataGridTableStyle()

TableStyle.MappingName = "datasettable1"


Me.datagrid1.TableStyles.Add(TableStyle)

Dim col0 As New DataGridTextBoxColumn()
col0.MappingName = "Column0Name"
col0.Width = 75



Dim col1 As New DataGridTextBoxColumn()

col1.MappingName = "Column1Name"
col1.Width = 75



'assume this is your unbound column
Dim col2 As New DataGridUnboundColumn()


col2.MappingName = "Column2Name" 'unbound
col2.Width = 75

'add unbound column first
TableStyle.GridColumnStyles.Add(col2)
TableStyle.GridColumnStyles.Add(col0)
TableStyle.GridColumnStyles.Add(col1)


Hope this helps. There might be a way to do it without defining your own tablestyle but im not sure.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top