9 Replies - 4227 Views - Last Post: 11 August 2011 - 07:19 AM Rate Topic: -----

#1 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

How to disable cells in VB.NET datagrid

Posted 10 August 2011 - 11:24 AM

Dear All,

1. Can anybody tell me how can i disable a cell of datagrid in vb.net
2. How can i show current date in datagrid cell

i have used this peace of code on form load event

DataGridView1.CurrentRow.Cells(7).Value = Now
DataGridView1.CurrentRow.Cells(0).ReadOnly = True

but it give me message object reference is not set to an instance of object what should i do to resolve these two issues.

Is This A Good Question/Topic? 0
  • +

Replies To: How to disable cells in VB.NET datagrid

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8922
  • View blog
  • Posts: 33,444
  • Joined: 12-June 08

Re: How to disable cells in VB.NET datagrid

Posted 10 August 2011 - 11:37 AM

Would your grid even have rows it in at that point? I mean if there is no "current row" that would be a problem.

This is easily determined by putting a break point on that first line and checking to see if 'current row' exists or not.
Was This Post Helpful? 0
  • +
  • -

#3 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

Re: How to disable cells in VB.NET datagrid

Posted 10 August 2011 - 12:10 PM

Yes it has current row
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8922
  • View blog
  • Posts: 33,444
  • Joined: 12-June 08

Re: How to disable cells in VB.NET datagrid

Posted 10 August 2011 - 12:20 PM

Okay then you attempting to access cells/columns before they are set.

Either you have no rows or cells.
Was This Post Helpful? 0
  • +
  • -

#5 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

Re: How to disable cells in VB.NET datagrid

Posted 11 August 2011 - 05:55 AM

I didn't understand please any body can help me.
Was This Post Helpful? 0
  • +
  • -

#6 Eloryan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-August 11

Re: How to disable cells in VB.NET datagrid

Posted 11 August 2011 - 06:25 AM

Hi naveed_786.
i would like to know the result message that will return the following code

MsgBox(DataGridView1.CurrentRow.Cells(7).ToString)


cause as modi123_1 said this error occurs if there is no Currentrow.
Was This Post Helpful? 0
  • +
  • -

#7 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

Re: How to disable cells in VB.NET datagrid

Posted 11 August 2011 - 06:44 AM

I got this message
Datagridview textboxcell{Columnindex = 7, Rowindex = 0}

Was This Post Helpful? 0
  • +
  • -

#8 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

Re: How to disable cells in VB.NET datagrid

Posted 11 August 2011 - 06:50 AM

Okay let me play my self
Was This Post Helpful? 0
  • +
  • -

#9 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

Re: How to disable cells in VB.NET datagrid

Posted 11 August 2011 - 07:04 AM

Okay when i write this code on click event of a buton

DataGridView1.CurrentRow.Cells(7).Value = Now

DataGridView1.CurrentRow.Cells("PR_NO").ReadOnly = True



It works fine but i want to write this code on form load event here it gives me error how to resolve it error is

"bject reference is not set to an instance of object"
Was This Post Helpful? 0
  • +
  • -

#10 naveed_786  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 306
  • Joined: 13-October 09

Re: How to disable cells in VB.NET datagrid

Posted 11 August 2011 - 07:19 AM

Here is the solution i have done it

    Private Sub dataGridView1_CellClick(ByVal sender As Object, _
    ByVal e As DataGridViewCellEventArgs) _
    Handles DataGridView1.CellClick

        DataGridView1.CurrentRow.Cells(0).ReadOnly = True
        DataGridView1.CurrentRow.Cells(7).Value = Now
    End Sub

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1