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
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
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).ColumnNa me = "myCol_Identifier"
oTable.Columns(1).ColumnNa me = "myCol_Text"
DataGrid1.DataSource = oTable
Notice that this will only work if you set the Datasource member of datagrid1 at runtime!
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("
oRead.Fill(oTable)
oTable.Columns(0).ColumnNa
oTable.Columns(1).ColumnNa
DataGrid1.DataSource = oTable
Notice that this will only work if you set the Datasource member of datagrid1 at runtime!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
myDataGrid.TableStyles[0].
myDataGrid.TableStyles[0].