rename a columns title in a dataGridView
Hi,
I'm filling a dataGrid with an Access database. But of course I want to change tittles of the fields. It seems only fields of type "string" change name. All other columns are staing the same name as originally in the database. How is this possible ? Someone know ? Do I use wrong code ? To be sure I started a new project and a fresh dataGridView to be sure I did not touch any properties.
The name "New" appears only on the columns that have a fieldtype: 'string'.
Code:
partial class Form1: Form
{
OleDbConnection DBConnection;
private void Form1_Load(object sender, EventArgs e)
{
string DataSource = "C:\\1.mdb";
DBConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + DataSource);
DBConnection.Open();
try {
OleDbDataAdapter Adapter = new OleDbDataAdapter("SELECT * " +
"FROM Rx ",
DBConnection);
DataSet ds = new DataSet();
Adapter.Fill(ds);
dataGrid.DataSource = ds;
ds.Tables[0].TableName = "Rx";
dataGrid.DataMember = "Rx";
for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
dataGrid.Columns[i].HeaderText = "New";
} finally {
DBConnection.Close();
rgds, Wilfried
http://www.mestdagh.biz