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
Solved

Add a column to a DataGridView using code

Posted on 2009-07-08
3
208 Views
Last Modified: 2013-12-17
I have a DataGridView connected to a DataSource.

How can I add the following column in code? I can get the column to appear, but it appears with no data in it.

HeaderText: Ref
DataPropertyName: ref
ColumnType: DataGridViewTextBoxColumn

Thanks
0
Comment
Question by:zattz
  • 2
3 Comments
 
LVL 8

Expert Comment

by:redpipe
ID: 24802121
If your DataGridView is connected to a DataSource, you have to add the column to the DataSource in order to make the column contain data, and be editable.
0
 
LVL 8

Accepted Solution

by:
redpipe earned 500 total points
ID: 24802152
Is 'ref' part of the select from the database, that comprise the rest of your DataSource? If so, you could add this column programatically by:
DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();
col.DataPropertyName="ref";
col.HeaderText="Ref";
YourDataGridView.Columns.Add(col);

Open in new window

0
 

Author Comment

by:zattz
ID: 24802201
Many thanks :)
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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