473,498 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to enable gridview column for editing in C#?

103 New Member
I have a datagridview populated by the following code:
Expand|Select|Wrap|Line Numbers
  1.   if (hasTime == true)
  2.             {
  3.  
  4.                 string hourQuery = string.Format("SELECT contact.contactID, contact.firstName, contact.lastName, hours.hoursWorked" +
  5.                            " FROM contact INNER JOIN hours ON contact.contactID=hours.contactID WHERE hours.fiscalYearID ={0}", selectedYearID.ToString());
  6.                 cmd.CommandText = hourQuery;
  7.                 cmd.Connection.Open();
  8.                 var dr = cmd.ExecuteReader();
  9.                 if (dr.HasRows == true)
  10.                 {
  11.                     DataTable cHours = new DataTable();
  12.                     cHours.Load(dr);
  13.                     bindings.DataSource = cHours;
  14.                     dgvTime.DataSource = bindings;
  15.                     cmd.Connection.Close();
  16.                 }
  17.                 foreach (DataGridViewColumn column in dgvTime.Columns)
  18.                 {
  19.                     if (column.HeaderText == "contactID") { column.HeaderText = "ID"; column.ReadOnly = true; column.Visible = false; column.Width = 50; }
  20.                     if (column.HeaderText == "firstName") { column.HeaderText = "First"; column.Width = 150; column.ReadOnly = true; }
  21.                     if (column.HeaderText == "lastName") { column.HeaderText = "Last"; column.Width = 150; column.ReadOnly = true; }
  22.                     if (column.HeaderText == "hoursWorked") { column.HeaderText = "Annual Hours"; column.Width = 150; column.ReadOnly = true; }
  23.                 }
  24.  
How do I allow hhe column hoursWorked to be editable? When I change column.ReadOnly to false, it fails.

Any help or insight would be grsatly appreciated.
Jan 27 '14 #1
0 985

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3465
by: Hans Merkl | last post by:
Hi, I was wondering if it's possible to bind the header text of a GridView column to a method of an object I have. At the moment I am setting the header texts in Page_Load but I was wondering if...
5
19020
by: misiek | last post by:
Hi all. I would like to know if it is possible to dynamically enable/disable row editing in GridView control in ASP.NET 2.0. I am asking because this feature should be enabled/disable depending...
1
1438
by: Keithb | last post by:
What is the best way to hide a GridView column? Thanks, Keith
1
27371
by: AD | last post by:
Hi, I have a problem where my text in a GridView column is being wrapped in the middle of the column and does not fill the full width of the column, any idea why this would happen, and how I can...
2
3918
by: =?Utf-8?B?SkRSYXZlbg==?= | last post by:
I have searched all over and can not seem to find an effective way to simply copy the contents of a ASP:gridview column to the clipboard based on a button or similar HTML or ASP.NET control. ASP...
2
8636
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, can someone please tell me how to make a gridview column fixed-width? When I resize the browser the columns auto adjust somehow and i can't figure out how to make that stop for one of my...
4
25502
by: Yin99 | last post by:
I have a Gridview binding to a DataTable source. I'd like to set the column with of the second column. I cannot do this apparently because when AutoGenerateColumns=true, they do not appear in the...
2
4376
by: =?Utf-8?B?ZG1idXNv?= | last post by:
How do I increase the default width of a gridview column (just one column, the 10th column, named "Notes")? In design mode, I changed the width properties of the HeaderStyle, ControlStyle, and...
1
1628
by: =?Utf-8?B?ZG1idXNv?= | last post by:
How do I increase the default width of a gridview column (just one column, the 10th column, named "Notes")? In design mode, I changed the width properties of the HeaderStyle, ControlStyle, and...
7
3112
by: Bobby Edward | last post by:
What is the formatstring for mm/dd/yy (gridview column)? I always want it to be 6 digits. Thanks.
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7205
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5462
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4590
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1419
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.