Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

Change mouse cursor when points to specific cell

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Suz - 31 Mar 2005 19:31 GMT
I am creating a linklabel look-a-link in a datagrid with the following code
by overriding the paint sub:

If column = 0 Or column = 3 Or column = 4 Then

               Dim UnderlineFont As New
Font(Me.DataGridTableStyle.DataGrid.Font, FontStyle.Underline)
               Dim rect As Rectangle = bounds
               Dim value As Object = GetColumnValueAtRow(source, rowNum)
               g.FillRectangle(backBrush, rect)
               g.DrawString(value.ToString, UnderlineFont, Brushes.Blue,
RectangleF.FromLTRB(rect.X, rect.Y, rect.Right, rect.Bottom))

           Else
               MyBase.Paint(g, bounds, source, rowNum, backBrush,
foreBrush, alignToRight)
           End If

I only create the linklabel look-alike in specific rows and columns. Now I
have to have the cursor change to a 'hand'  when the mouse moves over a cell.
Note! I am creating the datagrid programmatically so I do not know what rows
will contain a link (so I can not use the example by George Shepard in
sycfusion). Also, there is NOT a mouseup or mousedown event to work with. I
only want the cursor to change to a hand on a specific cell, not a whole row.

I have been trying to do with with the datagrid.hittestinfo but can't seem
the to get it.

Thanks!

Signature

Suz

Madhavi - 31 Mar 2005 19:45 GMT
Suz,

Try subclassing the DataGrid and override OnMouseEnter method. It the column
is of Type LinkLabelColumn then change the cursor style. This is what I did
for the Look a like linkLabel in my inherited DataGrid.

protected override void OnMouseMove(MouseEventArgs e){

DataGrid.HitTestInfo hti = HitTest(e.X, e.Y);

switch (hti.Type)

{

case DataGrid.HitTestType.Cell:

if
(TableStyles[0].GridColumnStyles[hti.Column].GetType().Name.Equals("LinkLabelColumn"))

{

this.Cursor = Cursors.Hand;

}

else

{

this.Cursor = Cursors.Arrow;

}

break;

}

}

>I am creating a linklabel look-a-link in a datagrid with the following code
> by overriding the paint sub:
[quoted text clipped - 29 lines]
>
> Thanks!
Suz - 31 Mar 2005 23:25 GMT
Hi Madhavi!

Thank you! It works ..... would you happen to know how I can interrigate the
contents of the cell to find out if it is blank or has a value. If it is
blank, then I do no want it to have a hand cursor.
The screen looks something like this

FileID    
             Date              Owner               Project
             Date              Owner               Project

So that every row in the FileID column has a 'linklabelcolumn'. The cursor
is a hand over the whole  FileID column. I think that if I can find  the
value in the in the cell, then I can change the cursor style based on the
contents of the cell.  

Again, thank you!

> Suz,
>
[quoted text clipped - 68 lines]
> >
> > Thanks!
Suz - 31 Mar 2005 23:25 GMT
Hi Madhavi!

Thank you! It works ..... would you happen to know how I can interrigate the
contents of the cell to find out if it is blank or has a value. If it is
blank, then I do no want it to have a hand cursor.
The screen looks something like this

FileID    
             Date              Owner               Project
             Date              Owner               Project

So that every row in the FileID column has a 'linklabelcolumn'. The cursor
is a hand over the whole  FileID column. I think that if I can find  the
value in the in the cell, then I can change the cursor style based on the
contents of the cell.  

Again, thank you!

> Suz,
>
[quoted text clipped - 68 lines]
> >
> > Thanks!
Suz - 31 Mar 2005 23:25 GMT
Hi Madhavi!

Thank you! It works ..... would you happen to know how I can interrigate the
contents of the cell to find out if it is blank or has a value. If it is
blank, then I do no want it to have a hand cursor.
The screen looks something like this

FileID    
             Date              Owner               Project
             Date              Owner               Project

So that every row in the FileID column has a 'linklabelcolumn'. The cursor
is a hand over the whole  FileID column. I think that if I can find  the
value in the in the cell, then I can change the cursor style based on the
contents of the cell.  

Again, thank you!

> Suz,
>
[quoted text clipped - 68 lines]
> >
> > Thanks!
Suz - 31 Mar 2005 23:25 GMT
Hi Madhavi!

Thank you! It works ..... would you happen to know how I can interrigate the
contents of the cell to find out if it is blank or has a value. If it is
blank, then I do no want it to have a hand cursor.
The screen looks something like this

FileName    
              DateDone              Owner               Project
              DateDone              Owner               Project

So that every row in the FileName column has a 'linklabelcolumn'. The cursor
is a hand over the whole  FileName column. I think that if I can find  the
value in the in the cell, then I can change the cursor style based on the
contents of the cell.  

Again, thank you!

> Suz,
>
[quoted text clipped - 68 lines]
> >
> > Thanks!
Suz - 01 Apr 2005 00:15 GMT
Madhavi!

I got it all working. Below is my modified code. Thanks so much for your
help. Sorry for the repeated posts. I get getting a bad verb error and didn't
realize my post was actually posting!

Private Sub dgMain_MouseMove( _
   ByVal sender As Object, _
   ByVal e As MouseEventArgs)
       ' **********************************
       Dim hti As DataGrid.HitTestInfo = dgMain.HitTest(e.X, e.Y)
       Select Case hti.Type
           Case DataGrid.HitTestType.Cell
               If
dgMain.TableStyles(0).GridColumnStyles(hti.Column).GetType.Name.Equals("DataGridColoredLinkLabel") Then
                   If dgMain.Item(hti.Row, hti.Column).ToString() <> "" Then
                       Me.Cursor = Cursors.Hand
                   Else
                       Me.Cursor = Cursors.Arrow
                   End If
               Else
                   Me.Cursor = Cursors.Arrow
               End If

       End Select

   End Sub

> Hi Madhavi!
>
[quoted text clipped - 86 lines]
> > >
> > > Thanks!
Madhavi - 01 Apr 2005 17:48 GMT
This was exactly what I was working on last week. So I could help you help
you.

Happy coding!!
Madhavi
> Madhavi!
>
[quoted text clipped - 132 lines]
>> > >
>> > > Thanks!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.