Link to home
Start Free TrialLog in
Avatar of connelvalentine
connelvalentine

asked on

Changing column headers in datagrid control

Hi,

I've bound my datagrid control to a dataset in my VB.NET application.
The datagrid is displaying the details perfectly. The data adapater is connecting to a SQL database.

Users will be expected to modify data in the data grid control. However, due to standards established, my field names in the database's table are fld_usercode, fld_username, fld_useremail etc.
Therefore, the column hearders of the datagrid control also display these field names. I want to be able to modify the column headers of the datagrid control with more user friendly names while being bound to the USERS table. Is this possible?

BR,
CV
ASKER CERTIFIED SOLUTION
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of connelvalentine
connelvalentine

ASKER

Hi webtubbs,

I've tried this, but as i open the form i get the following error:

An unhandled exception of type 'System.Data.ConstraintException' occurred in system.data.dll

Additional information: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

I've basically used the VB.NET interface to modify the SQL adapter, and i've entered alias names for each of my fields. This has modified the SQL statement accordingly. Unfortunately after doing so, i'm getting the above error. Removing the aliases enables the form to open again and display the data on the grid.

Any thoughts?
oh yes, forgot to mention that this line in my code is highlighted under the form load event:
sqlda_users.Fill(Ds_users, "tbl_users")
Right click datagrid. Edit columns
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

Sorry dont put it before loading the data but after that becuase it overwrite the HeaderNames
Hi Guys,

Hatem, datagrid.columns doesn't work in vb.net. I think you're referring to VB6

Actually i've found a solution to my problem.
In .NET custom columns can be done by using the TableStyles collection of the datagrid and the GridColumn Style collection in the TableStyle Collection. The TableStyle should be mapped to the table name in the dataset and one grid column style should be added for each field, mapped to the field in the table, and the custom text you'd want to appear can be placed in the "Header Text" field of the column style.

BR,
CV

Hi Connelvalentine,

First thanx for the points ... about my code it work in my vb.net 2005 app

as u c i used (dataGridView1) which is new in 2005 .

best regards