Solved

Datagrid No column names

Posted on 2004-04-21
5
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

690 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