newbie: trouble with DataGridTextBoxColumn

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

IDE: Visual Studio 2003 .NET
OS: XP Pro


SqlCommand cmd = sqlCon.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select OrderID from Orders";

SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.SelectCommand = cmd;
DataSet dsResult = new DataSet();
adapter.Fill(dsResult);

DataGridTableStyle tsl = new DataGridTableStyle();
DataGridColumnStyle testCol = new DataGridTextBoxColumn();
testCol.MappingName = "OrderID";
testCol.HeaderText = "Hello world";
testCol.Width = 150;
tsl.GridColumnStyles.Add(testCol);

dataGrid1.TableStyles.Add(tsl);
dataGrid1.DataSource = dsResult;
dataGrid1.DataMember = "Table";

When I run this script the columntext is OrderID, I thought it should be
"Hello world". What did I wrong here??

Regards

Jeff
 
You forgot to set the mappingname of the table style itself... ;) I have
encountered it long back
tsl.MappingName = "Orders"; //// Whatever the table name you might be
getting....
This will solve your ploblem

Regards,
Sanjeevakumar Hiremath

Proteans Software Solutions
__________________________
e-mail : (e-mail address removed)
Phone: 91-80-36880796
Office: 91-80-51217844
Fax : 91-80-51217536
MSN : (e-mail address removed)
YahooIM : jack_hide2000
 
Back
Top