Solved

Datagrid No column names

Posted on 2004-04-21
5
279 Views
Last Modified: 2010-04-15
I am trying to add some styles to my datagrid such as header text, width etc ... Every time I add something like that:

DataGridTextBoxColumn txtName = new DataGridTextBoxColumn();
txtName.HeaderText = "Name";
txtName.MappingName = "CompName";
txtName.Width = 150;

After I add that piece of code no data is displayed in my datagrid. can anyone help?
0
Comment
Question by:TransBind
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:eternal_21
ID: 10883141
Can you post the code where txtName is added to the styles collection, and where the DataGrid is bound to the data source?
0
 
LVL 7

Author Comment

by:TransBind
ID: 10883227
//part of the code where txtName is added to the styles collection:

DataGridTableStyle myStyle = new DataGridTableStyle();
myStyle.MappingName = "dtSKU";
myStyle.BackColor = System.Drawing.Color.Wheat;
myStyle.HeaderBackColor = System.Drawing.Color.Bisque;
myStyle.HeaderForeColor = System.Drawing.Color.DarkBlue;
myStyle.AlternatingBackColor = System.Drawing.Color.Yellow;

DataGridTextBoxColumn txtName = new DataGridTextBoxColumn();
txtName.HeaderText = "Name";
txtName.MappingName = "ProdName";
txtName.Width = 150;

myStyle.GridColumnStyles.Add(txtName);
myDataGrid.TableStyles.Add(myStyle);



//part of the code where DataGrid is bound to the data source:

myLCDConnection.Open();
string strSQU = txtSQU.Text.ToString();
string strSQL = "select stk_name from fstock where stk_code like '%" + strSQU + "%'";
SqlDataAdapter adapter = new SqlDataAdapter(strSQL,myLCDConnection);
SqlCommand myCommand = new SqlCommand(strSQL,myLCDConnection);
adapter.Fill(ds, "dtSKU");
myDataGrid.DataSource = ds.Tables[0].DefaultView;            
myLCDConnection.Close();


//this code does not generate any errors and works great until i add:
DataGridTextBoxColumn txtName = new DataGridTextBoxColumn();
txtName.HeaderText = "Name";
txtName.MappingName = "ProdName";
txtName.Width = 150;

after i add this no data is displayed in a datagrid
0
 
LVL 10

Accepted Solution

by:
eternal_21 earned 100 total points
ID: 10883317
Have you tried changing txtName.MappingName = "ProdName" to txtName.MappingName = "stk_name" ?
0
 
LVL 7

Author Comment

by:TransBind
ID: 10883439
:) thanks, I knew it was something silly
0
 
LVL 7

Author Comment

by:TransBind
ID: 10883463
do u know how to get the value of a cell inside a datagrid on double click event? if u do ... plz answer it here:

http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20960750.html



0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now