Solved

Add a column to a DataGridView using code

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

697 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