Solved

Datagrid No column names

Posted on 2004-04-21
5
283 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET(C#) Eliminating weekends from a date range 2 54
C# LINQ ForEach() question 6 89
Change to file doesn't show up 16 80
parsing question on dynamic concatenation 3 34
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.

730 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