Solved

Customize the column of Datagrid in VB.net

Posted on 2004-03-23
4
530 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:jra2002
4 Comments
 
LVL 15

Expert Comment

by:OMC2000
ID: 10657958
myDataGrid.TableStyles[0].GridColumnStyles[0].Width = 500
 myDataGrid.TableStyles[0].GridColumnStyles[1].Width = 280
 myDataGrid.TableStyles[0].GridColumnStyles[2].Width = 350

0
 
LVL 10

Expert Comment

by:GoodJun
ID: 10657977
right click the grid and select grid builder to customize it.
0
 
LVL 2

Expert Comment

by:HugoCode
ID: 10658236
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!
0
 
LVL 4

Accepted Solution

by:
Jarodtweiss earned 250 total points
ID: 10661202
As OMC2000 as said, the best way to do that is to use the TableStyles.
If you don't provide anything, .NET will build one itself, very basic.

In the designer, add a new TableStyle and then add some columns.
For this to work, you must :
- Set a name to your DataTable : myTable.Name = "MyTable"
- Set the MappingName for the Table style to your table name "MyTable"
- For each column, set the mapping name to the name of your datatables column

Then you can customize a lot : Width, readonly, maxlength, ....

Be Careful !
The settings of the table style (backcolor, ...) override the settings of the datagrid.
So you have to set your settings there !
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Regular expression help 2 34
VB.NET 2008 - Windows Protected Your PC 7 41
Syntax Issue with SSIS module 26 102
how to just get time from a date 6 32
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question