Solved

Operator '<>' is not defined for types 'System.Windows.Forms.DataGridViewCell' and 'System.Windows.Forms.DataGridViewCell'

Posted on 2014-01-20
5
412 Views
Last Modified: 2014-03-13
Hi

I'm trying to compile a bit of code that allows one click edit of a DatagridView. It inherits the the DataGridView class. However when I compile it I get the error

Operator '<>' is not defined for types 'System.Windows.Forms.DataGridViewCell' and 'System.Windows.Forms.DataGridViewCell' in the MouseDown Routine as below. I have also attached the whole class. Basically i would like the class to compile.


        ' Get clicked cell
        Dim clickedCell As DataGridViewCell = Me.Rows(hitInfo.RowIndex).Cells(hitInfo.ColumnIndex)



        ' If cell not current, try and make it so
        ' **** error occurs here *************
        If CurrentCell <> clickedCell Then
            ' Allow standard processing make clicked cell current
            MyBase.OnMouseDown(e)

            ' If this didn't happen (validation failed etc), abort
            If Me.CurrentCell <> clickedCell Then
                Return
            End If
        End If

'whole class file  below
'------------------------------------------------------------------------------------------------------
OneClickEditDataGrid.vb
0
Comment
Question by:capitaldev
  • 2
  • 2
5 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39793848
do you want to compare them in regards to the value or the position (row/column)

I would say you want to change to:
If Me.CurrentCell.ColumnIndex <> clickedCell.ColumnIndex Or  Me.CurrentCell.RowIndex <> clickedCell.RowIndexThen 

Open in new window


hope this helps
0
 

Author Comment

by:capitaldev
ID: 39793862
Thanks, I was thinking along the lines of creating an operating for it some how

Public shared Operater(datagridcell a, datagridcell b) as boolean

If   A.ColumnIndex <> B.ColumnIndex Or  A.CurrentCell.RowIndex <> B.Rowindex

end operator

but a get a compile error when i do this...  

Also I thought I may be missing a reference or something...
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39793889
you may also try out this:
If !Me.CurrentCell.Equals(clickedCell) then ...


apart from that (bare with me, vb.net is not my strong point)
Public shared Function AreDataGridCellsAtSameIndexes(datagridcell a, datagridcell b) as boolean

If   A.ColumnIndex <> B.ColumnIndex Or  A.CurrentCell.RowIndex <> B.Rowindex
   AreDataGridCellsAtSameIndexes = false
else 
   AreDataGridCellsAtSameIndexes = true
End if

end Function 

Open in new window


and it shall be used like this:

If !AreDataGridCellsAtSameIndexes (Me.CurrentCell , clickedCell) then ...
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 39793942
As you are storing a reference to a cell, you can just compare the references:

If Not Object.ReferenceEquals(CurrentCell, clickedCell) Then

Open in new window

0
 

Author Closing Comment

by:capitaldev
ID: 39927017
thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

743 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

15 Experts available now in Live!

Get 1:1 Help Now