Solved

Add a column to a DataGridView using code

Posted on 2009-07-08
3
204 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

11 Experts available now in Live!

Get 1:1 Help Now