Solved

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

Posted on 2014-01-20
5
431 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 143

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 143

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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