locked
change style button in datagridview RRS feed

  • Question

  • hi

    Add button to DataGridView


    I want to change my border style of button
    I want to 
    changing Cursor to put the hand in  hover cell button only
    I want to add
    image to button  from resource

    my code

     Dim column As New DataGridViewButtonColumn()
                column.Name = "details"
                column.UseColumnTextForButtonValue = True
                column.Text = "show"
                DATAGRID_SERVER.Columns.Add(column)


    • Edited by ahmeddc Monday, October 1, 2018 1:57 PM
    Monday, October 1, 2018 1:24 PM

Answers

  • HI

    Thank you all for help
    What about this request

    I want to add image to button  from resource

    I have an old example that does this, done in VS2010 but still works fine in VS2017.

    https://1drv.ms/u/s!AtGAgKKpqdWjgypvYOKMd8PydKTh


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by ahmeddc Monday, October 1, 2018 9:25 PM
    Monday, October 1, 2018 7:30 PM

All replies

  • Something like this?

    Dont think there is a way to change the style of box without painting it yourself. Maybe an image column would be a better option which is what I always use... 

        Private Sub DataGridView1_MouseMove(sender As Object, e As MouseEventArgs) Handles DataGridView1.MouseMove
            If DataGridView1.CurrentCell.OwningColumn.Name = "YourButtonColName" Then
                Cursor = Cursors.Hand
            Else
                Cursor = Cursors.Default
            End If
        End Sub
    Edit-actually this wont work. May have to use HitTest on mouse position


    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi



    • Edited by Gtripodi Monday, October 1, 2018 2:05 PM
    Monday, October 1, 2018 1:58 PM
  • Hi

    You could use almost any control in place of a Button, just using the control  mouse click event handlers in a similar way that you use a Button. For example, you could have a PictureBox with all sorts of Image/style  applied and kust use the Click event.


    Regards Les, Livingston, Scotland

    Monday, October 1, 2018 2:16 PM
  • Given in this example column 0 is a DataGridViewButton column it has a hand cusor while the other the default cursor.

    Private Sub DataGridView1_CellMouseEnter(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellMouseEnter
        If e.ColumnIndex = 0 AndAlso e.RowIndex >= 0 Then
            DataGridView1.Cursor = Cursors.Hand
        Else
            DataGridView1.Cursor = Cursors.Default
        End If
    End Sub


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, October 1, 2018 2:34 PM
  • HI

    Thank you all for help
    What about this request

    I want to add image to button  from resource

    Monday, October 1, 2018 6:17 PM
  • HI

    Thank you all for help
    What about this request

    I want to add image to button  from resource

    I have an old example that does this, done in VS2010 but still works fine in VS2017.

    https://1drv.ms/u/s!AtGAgKKpqdWjgypvYOKMd8PydKTh


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by ahmeddc Monday, October 1, 2018 9:25 PM
    Monday, October 1, 2018 7:30 PM