DataGridViewButtonCell Text-VBForums
Results 1 to 4 of 4

Thread: DataGridViewButtonCell Text

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2017
    Posts
    121

    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
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,823

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2017
    Posts
    121

    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
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,823

    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.
    Last edited by jmcilhinney; Nov 10th, 2017 at 12:08 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.