9 Replies - 812 Views - Last Post: 11 December 2012 - 09:46 AM Rate Topic: -----

#1 Cowski  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 10-November 07

Set column in a Datagridview to be editable

Posted 06 December 2012 - 11:54 AM

I've been at this on/off for about a week now. I put it to the side & move onto other things and now I'm back to it.
I have a datagridview (dgvScheduleInfo). In its properties I have the "ReadOnly" set to true. I have 6 columns (0-5). The last column ("Notes") I want to make editable if someone clicks on a "Edit Notes" button. Sounds simple enough.

I've used the following code to no avail:

dgvScheduleInfo.Columns("Notes").ReadOnly = False

The code above errors out with a "Object reference not set to an instance of an object."

I've tried hard-coding a value for testing purposes:

dgvScheduleInfo.Rows(3).Cells(5).ReadOnly = False


And this is ultimately what I want to work:

dgvScheduleInfo.Rows(dgvScheduleInfo.CurrentRow.Index).Cells(5).ReadOnly = False


When I step through the code, I only get an error on the one I specified. Other then that though the code steps through fine but does not set the column I'm requesting to be editable.

Now yet another curveball...
If I use:

dgvScheduleInfo.ReadOnly = False


It works fine but turns ALL the cells on which I don't want. I only want the "Notes" (or column 5) to be editable.

I've changed the "EditMode" to a couple of different things as well. Nothing.

Hopefully it's something very easy I'm missing.

Is This A Good Question/Topic? 0
  • +

Replies To: Set column in a Datagridview to be editable

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9047
  • View blog
  • Posts: 33,959
  • Joined: 12-June 08

Re: Set column in a Datagridview to be editable

Posted 06 December 2012 - 12:06 PM

You are certain your column's key is "Notes"?
Was This Post Helpful? 0
  • +
  • -

#3 Cowski  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 10-November 07

Re: Set column in a Datagridview to be editable

Posted 06 December 2012 - 12:44 PM

Double checked:
Under the "Data" section:
"DataPropertyName" -- "Notes"

Under the "Design" section:
"(Name)" -- "Notes"

Funny thing about this is it WAS "NotesDataGridViewTextBoxColumn" so I took off everything but "Notes" and still got the same results. Nothing.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9047
  • View blog
  • Posts: 33,959
  • Joined: 12-June 08

Re: Set column in a Datagridview to be editable

Posted 06 December 2012 - 12:54 PM

Then slap a breakpoint right before your line and check out what that column's name is.

Something's all mussed up since things like this work fine:

        Dim foo As New DataGridView
        foo.Columns.Add("test", "Header Text")
        foo.Columns.Add("test2", "Header Text2")
        foo.Columns("test2").ReadOnly = False

Was This Post Helpful? 0
  • +
  • -

#5 Cowski  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 10-November 07

Re: Set column in a Datagridview to be editable

Posted 06 December 2012 - 01:32 PM

Ok...I'm not doing any .Add in my code. I used the "DataGridView Tasks" arrow on the top right hand corner of my datagridview.

The only code in my cmdEditNotes button is:

dgvScheduleInfo.Columns("Notes").ReadOnly = False


I put a breakpoint on that and hovered over it when I got to it. Below is what I found:
Posted Image

Sorry...here's a better screenshot of what I have:

Posted Image
Was This Post Helpful? 0
  • +
  • -

#6 Cowski  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 10-November 07

Re: Set column in a Datagridview to be editable

Posted 11 December 2012 - 08:51 AM

Wow...no one has any ideas on this one? Did I stump the crew?
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9047
  • View blog
  • Posts: 33,959
  • Joined: 12-June 08

Re: Set column in a Datagridview to be editable

Posted 11 December 2012 - 09:16 AM

... that or it wasn't explained well enough on what is going on and people have moved on?
Was This Post Helpful? 0
  • +
  • -

#8 Cowski  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 10-November 07

Re: Set column in a Datagridview to be editable

Posted 11 December 2012 - 09:18 AM

Wasn't explained well enough? Sorry my screenshots & code weren't enough.

Sheesh!
Was This Post Helpful? 0
  • +
  • -

#9 Cowski  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 10-November 07

Re: Set column in a Datagridview to be editable

Posted 11 December 2012 - 09:27 AM

Personally I'd like to know how I didn't explain this well enough. I take great pride in trying to not be vague in asking my questions so not to leave any stone unturned & that I did, in fact try different things before I reached out for help in a forum where, from what I read, is friendly.

Then to have you come along & say I didn't explain myself well enough tends to lead me to believe that you didn't read my OP well enough or my replies.

I gave you code I'm using, screenshots, above & beyond what I've seen others provide in here & then you say I didn't explain myself well enough. I can get more detailed but I don't want to insult your intelligence. I figured everyone in here was above that.

Sorry to have bothered anyone.
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9047
  • View blog
  • Posts: 33,959
  • Joined: 12-June 08

Re: Set column in a Datagridview to be editable

Posted 11 December 2012 - 09:46 AM

Quote

Then to have you come along & say I didn't explain myself well enough tends to lead me to believe that you didn't read my OP well enough or my replies.

The response was an alternative theory to a backhanded bump - nothing more. If you have further questions you can shoot me a pm.


In short - I gave you a chunk of code that shows you _CAN_ change the read only status of a column. I have zero idea what you changed in your project or what you have going on that may be blocking that, but yes.. yes you can change the read only status. I do it constantly on projects going out the door to control the user input work flow.

Quote

Personally I'd like to know how I didn't explain this well enough. I take great pride in trying to not be vague in asking my questions so not to leave any stone unturned & that I did, in fact try different things before I reached out for help in a forum where, from what I read, is friendly.

Sure you explained what was going on, and plus points for showing what you have tried, but what was left out was explaining what you did to the grid to get it in a state where the column read only status isn't being set. There are sacks full of ways you could have messed something up and, at best, I can only shoot off into the dark on some of them.

Quote

I gave you code I'm using, screenshots, above & beyond what I've seen others provide in here & then you say I didn't explain myself well enough.

Read above.

Quote

I can get more detailed but I don't want to insult your intelligence. I figured everyone in here was above that.

Excuse me?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1