Solved

Datagrid No column names

Posted on 2004-04-21
5
275 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
Comment Utility
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
Comment Utility
//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
Comment Utility
Have you tried changing txtName.MappingName = "ProdName" to txtName.MappingName = "stk_name" ?
0
 
LVL 7

Author Comment

by:TransBind
Comment Utility
:) thanks, I knew it was something silly
0
 
LVL 7

Author Comment

by:TransBind
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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