VB.Net! Damn DataGrid Column Names!

Get help on programming - C++, Java, Delphi, etc.
Post Reply
GoodGirl
Registered User
Posts: 3
Joined: 05 Nov 2006, 02:00
Contact:

VB.Net! Damn DataGrid Column Names!

Post by GoodGirl »

Hallo

Can anybody tell me how to change the column name of a DataGrid Column, Not in Asp .Net, but in Windows Based. Please.

They said that i should try the following, but it does not work.

Suppose your datagrid is dgEmployees

Dim dgTS As New DataGridTableStyle
Dim ColStyle As New DataGridTextBoxColumn

ColStyle.MappingName = "Emp_Name"
ColStyle.HeaderText = "Employee Name"
dgTS.GridColumnStyles.Add(ColStyle)

dgEmployees.TableStyles.Add(dgTS)
viceroy
Registered User
Posts: 3565
Joined: 27 Mar 2006, 02:00
Location: I forget

Post by viceroy »

Well I usually create a datatable and then datacolumns and then assign the datatable to the datagrid and the column names pass through

eg

dim tbl as datatable
dim col1 as datacolumn
dim col2 as datacolumn

col1.columnname = "Column1"
col1.caption = "Column1"

col2.columnname = "Column2"
col2.caption = "Column2"

tbl.columns.add(col1)
tbl.columns.add(col2)

datagrid1.datasource = tbl


but thats just me...I'm no .net programmer though, just a database programmer
Image
GoodGirl
Registered User
Posts: 3
Joined: 05 Nov 2006, 02:00
Contact:

Post by GoodGirl »

Ok that is fine, but how do I add the data from the database then, datatable source?
viceroy
Registered User
Posts: 3565
Joined: 27 Mar 2006, 02:00
Location: I forget

Post by viceroy »

oh okay well you do the following

I'm assuming that you've already setup your connection and have set rs as the recordset.

Dim r As DataRow
r("Column1") = rs(0).Value
r("column2") = rs(1).Value
Image
SBSP
Registered User
Posts: 3124
Joined: 09 May 2006, 02:00
Location: Centurion

Post by SBSP »

cant you set the datagrid's datasource to get a data from an ADODC.
control thats connected to an ODBC connection.

Then use viceroy's method to change the table names.

Sorry i used to be a bit of a VB6 coder.
viceroy
Registered User
Posts: 3565
Joined: 27 Mar 2006, 02:00
Location: I forget

Post by viceroy »

Nah, that wouldn't work, well it would work to assign the datagrids datasource directly to the adodb or whatever but then you'd still need to assign table names yourself, or maybe not...I've forgotten much these last few years
Image
Post Reply