Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Datagrid No column names

Posted on 2004-04-21
5
Medium Priority
?
287 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 400 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

877 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