Results 1 to 4 of 4

Thread: DataGridViewButtonCell Text

Hybrid View

  1. #1

    Thread Starter
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    DataGridViewButtonCell Text

    This is probably easier than what I am making it out to be. I am trying to simply insert a string from a hidden column(MachID) within a datagridview to a buttoncell text value. I cant seem to get a hold of the button cell ".text' property no matter how I cast things. This code just freezes.

    Code:
                    Dim BtnCol As New DataGridViewButtonColumn
                    With BtnCol
                        .HeaderText = "Select"
                        .Name = "BtnCol"
                        .UseColumnTextForButtonValue = True
                    End With
                    .Columns.Add(BtnCol)
    Code:
                For Each DGVRow As DataGridViewRow In DGV_Machine.Rows
                    Dim BtnCell As DataGridViewButtonCell = CType(DGVRow.Cells("BtnCol"), DataGridViewButtonCell)
                    BtnCell.Value = DGVRow.Cells("MachID").Value.ToString
                Next

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: DataGridViewButtonCell Text

    The first code snippet includes this:
    vb.net Code:
    1. .UseColumnTextForButtonValue = True
    If you want a different value for each cell then why are you telling the column to use the column text for every cell value?

  3. #3

    Thread Starter
    Fanatic Member kpmc's Avatar
    Join Date
    Sep 2017
    Posts
    1,012

    Re: DataGridViewButtonCell Text

    Quote Originally Posted by jmcilhinney View Post
    The first code snippet includes this:
    vb.net Code:
    1. .UseColumnTextForButtonValue = True
    If you want a different value for each cell then why are you telling the column to use the column text for every cell value?
    I did see that before I left and commented it out, For some reason the loop is freezing without an exception. breakpoints arent helping either

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: DataGridViewButtonCell Text

    A loop itself can't really freeze. One of the lines in the loop would freeze, i.e. a method call would not return. Setting a breakpoint and stepping through the code would you allow to determine which one and what row you were using at the time, so breakpoints will help if you use one properly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width