Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

16 Experts available now in Live!

Get 1:1 Help Now