Solved

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

Posted on 2014-01-20
5
425 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding bootstrap to only Content page and NOT master page 1 50
Syntax Issue with SSIS module 26 105
Passing data between Forms 3 20
System.net.Sockets Error 5 28
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…

828 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