Solved

Add a column to a DataGridView using code

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 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