Solved

Add a column to a DataGridView using code

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

896 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

14 Experts available now in Live!

Get 1:1 Help Now