Link to home
Start Free TrialLog in
Avatar of jra2002
jra2002

asked on

Customize the column of Datagrid in VB.net

In the VB.net from the Database I am getting the following columns
Emp_Name, Rate_of_change and Salary

In the DataGrid I want to customize this columns as with the
following captions

Employee name
Rate of Change
Salary

correspondingly I want to set the width as

500 (for Employee name)
280 (for Rate of Change)
350 (for Salary)

Could you please let me know how to do this

Thanks
Avatar of OMC2000
OMC2000
Flag of Russian Federation image

myDataGrid.TableStyles[0].GridColumnStyles[0].Width = 500
 myDataGrid.TableStyles[0].GridColumnStyles[1].Width = 280
 myDataGrid.TableStyles[0].GridColumnStyles[2].Width = 350

Avatar of GoodJun
GoodJun

right click the grid and select grid builder to customize it.
The easiest way to change the column header would be modifying your statement.
F.e.:
Instead of
"Select [ID], description from xyz"
You can use
"Select MyColumn1=[ID], MyColumn2=description from xyz"

Thats not beautiful, but is the simplest way to solve it.
A better method would be:

Dim oTable As New DataTable("test")
Dim oRead As New SqlClient.SqlDataAdapter("Select ID, description from xyz", oCon)
oRead.Fill(oTable)
oTable.Columns(0).ColumnName = "myCol_Identifier"
oTable.Columns(1).ColumnName = "myCol_Text"
DataGrid1.DataSource = oTable

Notice that this will only work if you set the Datasource member of datagrid1 at runtime!
ASKER CERTIFIED SOLUTION
Avatar of Jarodtweiss
Jarodtweiss

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