Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. datagridview button column - text not displaying [Solved]

datagridview button column - text not displaying [Solved]

Scheduled Pinned Locked Moved Visual Basic
csharptutorialquestion
16 Posts 6 Posters 26 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    You're right. I've taken the example, compiled it using SharpDevelop, the example shows the exact same code;

    ' Add a button column.
    Dim buttonColumn As New DataGridViewButtonColumn()
    buttonColumn.HeaderText = ""
    buttonColumn.Name = "Status Request"
    buttonColumn.Text = "TestText"
    buttonColumn.UseColumnTextForButtonValue = True

    The HeaderText is the caption of the column, my bad. And yes, this code should have changed the caption of the button within the buttoncolumn. It seems that the example works. Can you post your version of the code?

    I are Troll :suss:

    S Offline
    S Offline
    Simon_Whale
    wrote on last edited by
    #5

    Thanks for this Ed

    Private Sub Properties_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    'set the screen size according to values in the app.config
    Me.Width = My.Settings.x
    Me.Height = My.Settings.y

        'load in the list of countries they can use
        'Dim cList As New List(Of ClientHome.vb.Countries)
    
        'Dim x As New ClientHome.vb.Buildings
        'cList = x.Countries
        'cbCountries.DataSource = cList
        'x = Nothing
    
        'expiry date
        'dtBldExpiry.Value = DateAdd(DateInterval.Day, 365, dtBldStart.Value)
        'dtCntExpiry.Value = DateAdd(DateInterval.Day, 365, dtCntStart.Value)
    
        'the question textbox in the grid
        Dim xy As New DataGridViewTextBoxColumn
        xy.HeaderText = "Question"
        Me.DataGridView1.Columns.Add(xy)
    
        'drop down list on grid
        Dim xx As New DataGridViewComboBoxColumn
        xx.Name = "YesNo"
        xx.Items.Add("Yes")
        xx.Items.Add("No")
        Me.DataGridView1.Columns.Add(xx)
    
        'the Answer Question
        Dim yx As New DataGridViewTextBoxColumn
        yx.HeaderText = "Answer"
        Me.DataGridView1.Columns.Add(yx)
    
        'the view button
        ' Add a button column. 
        Dim buttonColumn As New DataGridViewButtonColumn()
        buttonColumn.Name = "Requests"
        buttonColumn.Text = "Requests"
        buttonColumn.UseColumnTextForButtonValue = True
        DataGridView1.Columns.Add(buttonColumn)
    End Sub
    

    thats it Ed, there is a datagridview control on the form Many Thanks Simon

    L 1 Reply Last reply
    0
    • S Simon_Whale

      Thanks for this Ed

      Private Sub Properties_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      'set the screen size according to values in the app.config
      Me.Width = My.Settings.x
      Me.Height = My.Settings.y

          'load in the list of countries they can use
          'Dim cList As New List(Of ClientHome.vb.Countries)
      
          'Dim x As New ClientHome.vb.Buildings
          'cList = x.Countries
          'cbCountries.DataSource = cList
          'x = Nothing
      
          'expiry date
          'dtBldExpiry.Value = DateAdd(DateInterval.Day, 365, dtBldStart.Value)
          'dtCntExpiry.Value = DateAdd(DateInterval.Day, 365, dtCntStart.Value)
      
          'the question textbox in the grid
          Dim xy As New DataGridViewTextBoxColumn
          xy.HeaderText = "Question"
          Me.DataGridView1.Columns.Add(xy)
      
          'drop down list on grid
          Dim xx As New DataGridViewComboBoxColumn
          xx.Name = "YesNo"
          xx.Items.Add("Yes")
          xx.Items.Add("No")
          Me.DataGridView1.Columns.Add(xx)
      
          'the Answer Question
          Dim yx As New DataGridViewTextBoxColumn
          yx.HeaderText = "Answer"
          Me.DataGridView1.Columns.Add(yx)
      
          'the view button
          ' Add a button column. 
          Dim buttonColumn As New DataGridViewButtonColumn()
          buttonColumn.Name = "Requests"
          buttonColumn.Text = "Requests"
          buttonColumn.UseColumnTextForButtonValue = True
          DataGridView1.Columns.Add(buttonColumn)
      End Sub
      

      thats it Ed, there is a datagridview control on the form Many Thanks Simon

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #6

      Simon_Whale wrote:

      there is a datagridview control on the form

      With or without the correct caption on the buttons? I'll send my version by mail :)

      I are Troll :suss:

      S 1 Reply Last reply
      0
      • L Lost User

        Simon_Whale wrote:

        there is a datagridview control on the form

        With or without the correct caption on the buttons? I'll send my version by mail :)

        I are Troll :suss:

        S Offline
        S Offline
        Simon_Whale
        wrote on last edited by
        #7

        There is no captions on the button for the code i sent but im after putting a caption on the button for the users to press once again many thanks for your help SImon

        1 Reply Last reply
        0
        • L Lost User

          Simon_Whale wrote:

          Runs with no errors but the text doesn't show up. Any ideas?

          Yup, you set the HeaderText[^] property to Nothing. Try something like this;

          buttonColumn.HeaderText = "Hello World"

          I are Troll :suss:

          S Offline
          S Offline
          Simon_Whale
          wrote on last edited by
          #8

          Ed, Thank you, you are a genius worked out the problem from your example. During my experimentation / design layouts i wasn't adding a datasource to the grid. so it was displaying the first empty row. I then created a simple list of integers and set that to the datasource of the datagridview and the text shows up on the button as expected. could you assume this is how its suppose to work? Many Thanks Simon

          L 1 Reply Last reply
          0
          • S Simon_Whale

            Ed, Thank you, you are a genius worked out the problem from your example. During my experimentation / design layouts i wasn't adding a datasource to the grid. so it was displaying the first empty row. I then created a simple list of integers and set that to the datasource of the datagridview and the text shows up on the button as expected. could you assume this is how its suppose to work? Many Thanks Simon

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #9

            Simon_Whale wrote:

            Thank you, you are a genius worked out the problem from your example.

            Glad that it helped, but you're the one who worked it out :)

            Simon_Whale wrote:

            I then created a simple list of integers and set that to the datasource of the datagridview and the text shows up on the button as expected. could you assume this is how its suppose to work?

            It's one way that it can work - there's a lot of ways to fill a datagridview. And yes, it would be a good way; it's easy to read, easy to comprehend and thus, easy on maintenance.

            I are Troll :suss:

            1 Reply Last reply
            0
            • S Simon_Whale

              Guys and Gals, i have the following example VB.NET 2008

                  ' Add a button column. 
                  Dim buttonColumn As New DataGridViewButtonColumn()
                  buttonColumn.HeaderText = ""
                  buttonColumn.Name = "Status Request"
                  buttonColumn.Text = "Request Status"
                  buttonColumn.UseColumnTextForButtonValue = True
                  datagridview1.columns.add(buttoncolumn)
              

              Runs with no errors but the text doesn't show up. Any ideas? Thanks Simon

              modified on Wednesday, March 31, 2010 7:25 AM

              D Offline
              D Offline
              David Mujica
              wrote on last edited by
              #10

              I'm having the same problem. I read the postings, but I don't understand how this was solved. Here is my code snipet:

              Dim dgBtnCol As New DataGridViewButtonColumn()

              dgBtnCol.Name = "SelBtn"
              dgBtnCol.Text = "Select"

              DataGridView1.Columns.Add(dgBtnCol)
              Me.DataGridView1.DataSource = DT ' The datatable is already populated with data at this point

              The grid displays, but the caption on the button is nothing. How did the original poster solve this ? I forgot to add the following line of code .... dgBtnCol.UseColumnTextForButtonValue = True Regards, David

              S 1 Reply Last reply
              0
              • D David Mujica

                I'm having the same problem. I read the postings, but I don't understand how this was solved. Here is my code snipet:

                Dim dgBtnCol As New DataGridViewButtonColumn()

                dgBtnCol.Name = "SelBtn"
                dgBtnCol.Text = "Select"

                DataGridView1.Columns.Add(dgBtnCol)
                Me.DataGridView1.DataSource = DT ' The datatable is already populated with data at this point

                The grid displays, but the caption on the button is nothing. How did the original poster solve this ? I forgot to add the following line of code .... dgBtnCol.UseColumnTextForButtonValue = True Regards, David

                S Offline
                S Offline
                Simon_Whale
                wrote on last edited by
                #11

                Below is what i have working in a project

                Private Sub CreateGrid(ByRef data As DataView)
                    'the questionno
                    Dim BrokerNo As New DataGridViewTextBoxColumn
                    BrokerNo.HeaderText = "Broker Ref"
                    BrokerNo.DataPropertyName = "brokerref"
                    BrokerNo.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
                    Me.DataGridView1.Columns.Add(BrokerNo)
                
                
                    'the question textbox in the grid
                    Dim BrokersName As New DataGridViewTextBoxColumn
                    BrokersName.HeaderText = "Broker Name"
                    BrokersName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
                    BrokersName.DataPropertyName = "brokername"
                    Me.DataGridView1.Columns.Add(BrokersName)
                
                
                    'drop down list on grid
                    Dim BrokerStatus As New DataGridViewTextBoxColumn
                    BrokerStatus.DataPropertyName = "status"
                    BrokerStatus.HeaderText = "Status"
                    BrokerStatus.Name = "Status"
                    Me.DataGridView1.Columns.Add(BrokerStatus)
                
                
                    'the Answer Question
                    Dim Address As New DataGridViewTextBoxColumn
                    Address.Name = "Address"
                    Address.DataPropertyName = "address"
                    Address.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
                    Me.DataGridView1.Columns.Add(Address)
                
                
                
                    Dim TelNo As New DataGridViewTextBoxColumn
                    TelNo.HeaderText = "Tel No"
                    TelNo.DataPropertyName = "telno"
                    TelNo.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
                    Me.DataGridView1.Columns.Add(TelNo)
                
                
                    Dim buttonColumn As New DataGridViewButtonColumn()
                    buttonColumn.HeaderText = "View"
                    buttonColumn.Text = "View"
                    buttonColumn.UseColumnTextForButtonValue = True
                    buttonColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
                    buttonColumn.FlatStyle = FlatStyle.Standard
                    DataGridView1.Columns.Add(buttonColumn)
                
                
                    DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen
                    DataGridView1.DataSource = data
                
                  End Sub
                

                As barmey as a sack of badgers

                D 1 Reply Last reply
                0
                • S Simon_Whale

                  Below is what i have working in a project

                  Private Sub CreateGrid(ByRef data As DataView)
                      'the questionno
                      Dim BrokerNo As New DataGridViewTextBoxColumn
                      BrokerNo.HeaderText = "Broker Ref"
                      BrokerNo.DataPropertyName = "brokerref"
                      BrokerNo.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
                      Me.DataGridView1.Columns.Add(BrokerNo)
                  
                  
                      'the question textbox in the grid
                      Dim BrokersName As New DataGridViewTextBoxColumn
                      BrokersName.HeaderText = "Broker Name"
                      BrokersName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
                      BrokersName.DataPropertyName = "brokername"
                      Me.DataGridView1.Columns.Add(BrokersName)
                  
                  
                      'drop down list on grid
                      Dim BrokerStatus As New DataGridViewTextBoxColumn
                      BrokerStatus.DataPropertyName = "status"
                      BrokerStatus.HeaderText = "Status"
                      BrokerStatus.Name = "Status"
                      Me.DataGridView1.Columns.Add(BrokerStatus)
                  
                  
                      'the Answer Question
                      Dim Address As New DataGridViewTextBoxColumn
                      Address.Name = "Address"
                      Address.DataPropertyName = "address"
                      Address.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
                      Me.DataGridView1.Columns.Add(Address)
                  
                  
                  
                      Dim TelNo As New DataGridViewTextBoxColumn
                      TelNo.HeaderText = "Tel No"
                      TelNo.DataPropertyName = "telno"
                      TelNo.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
                      Me.DataGridView1.Columns.Add(TelNo)
                  
                  
                      Dim buttonColumn As New DataGridViewButtonColumn()
                      buttonColumn.HeaderText = "View"
                      buttonColumn.Text = "View"
                      buttonColumn.UseColumnTextForButtonValue = True
                      buttonColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
                      buttonColumn.FlatStyle = FlatStyle.Standard
                      DataGridView1.Columns.Add(buttonColumn)
                  
                  
                      DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGreen
                      DataGridView1.DataSource = data
                  
                    End Sub
                  

                  As barmey as a sack of badgers

                  D Offline
                  D Offline
                  David Mujica
                  wrote on last edited by
                  #12

                  Thanks for the quick reply. After looking at my code more closely, I was missing the following: dgBtnCol.UseColumnTextForButtonValue = True My code is now working. Thanks.

                  H 1 Reply Last reply
                  0
                  • D David Mujica

                    Thanks for the quick reply. After looking at my code more closely, I was missing the following: dgBtnCol.UseColumnTextForButtonValue = True My code is now working. Thanks.

                    H Offline
                    H Offline
                    HomeSen
                    wrote on last edited by
                    #13

                    Another workaround is to set the NullValue of the column to the desired text. In a project of mine I have a DataGridView where the user can add rows manually. The text for the button didn't appear and nothing seemed to work. I then remembered that there is always a NullValue property and after I set this, the text appeared on the button ;)

                    DataGridViewCellStyle8.NullValue = "Some Text"
                    Me.AddStillstand.DefaultCellStyle = DataGridViewCellStyle8
                    Me.AddStillstand.HeaderText = ""
                    Me.AddStillstand.Text = "Some Text"

                    Just in case someone else is having a similar issue ;)

                    B 1 Reply Last reply
                    0
                    • S Simon_Whale

                      Guys and Gals, i have the following example VB.NET 2008

                          ' Add a button column. 
                          Dim buttonColumn As New DataGridViewButtonColumn()
                          buttonColumn.HeaderText = ""
                          buttonColumn.Name = "Status Request"
                          buttonColumn.Text = "Request Status"
                          buttonColumn.UseColumnTextForButtonValue = True
                          datagridview1.columns.add(buttoncolumn)
                      

                      Runs with no errors but the text doesn't show up. Any ideas? Thanks Simon

                      modified on Wednesday, March 31, 2010 7:25 AM

                      A Offline
                      A Offline
                      Ajit Yagnesh
                      wrote on last edited by
                      #14

                      The code is working. just make sure that you apply this after assigning the datasource to your grid control. Step 1. After assign datasource to grid. // Add a button column. DataGridViewButtonColumn buttonColumn = new DataGridViewButtonColumn(); buttonColumn.HeaderText = ""; buttonColumn.Name = "Status Request"; buttonColumn.Text = "Request Status"; buttonColumn.UseColumnTextForButtonValue = true; dataGridView1.Columns.Add(buttonColumn); step2. just after adding the columns register your click event like below. // Add a CellClick handler to handle clicks in the button column. dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick); step 3. now on below event, void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) make sure which button is clicked when multiple are there. if (e.RowIndex < 0 || e.ColumnIndex != dataGridView1.Columns["Status Request"].Index) return; // Retrieve the task ID. Int32 taskID = (Int32)dataGridView1[0, e.RowIndex].Value; // Retrieve the Employee object from the "Assigned To" cell. Employee assignedTo = dataGridView1.Rows[e.RowIndex] .Cells["Assigned To"].Value as Employee; ======================== Ref: http://msdn.microsoft.com/en-us/library/ms171619.aspx[^]

                      hello give me code

                      S 1 Reply Last reply
                      0
                      • A Ajit Yagnesh

                        The code is working. just make sure that you apply this after assigning the datasource to your grid control. Step 1. After assign datasource to grid. // Add a button column. DataGridViewButtonColumn buttonColumn = new DataGridViewButtonColumn(); buttonColumn.HeaderText = ""; buttonColumn.Name = "Status Request"; buttonColumn.Text = "Request Status"; buttonColumn.UseColumnTextForButtonValue = true; dataGridView1.Columns.Add(buttonColumn); step2. just after adding the columns register your click event like below. // Add a CellClick handler to handle clicks in the button column. dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick); step 3. now on below event, void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) make sure which button is clicked when multiple are there. if (e.RowIndex < 0 || e.ColumnIndex != dataGridView1.Columns["Status Request"].Index) return; // Retrieve the task ID. Int32 taskID = (Int32)dataGridView1[0, e.RowIndex].Value; // Retrieve the Employee object from the "Assigned To" cell. Employee assignedTo = dataGridView1.Rows[e.RowIndex] .Cells["Assigned To"].Value as Employee; ======================== Ref: http://msdn.microsoft.com/en-us/library/ms171619.aspx[^]

                        hello give me code

                        S Offline
                        S Offline
                        Simon_Whale
                        wrote on last edited by
                        #15

                        Mate this was solved last year

                        As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.

                        1 Reply Last reply
                        0
                        • H HomeSen

                          Another workaround is to set the NullValue of the column to the desired text. In a project of mine I have a DataGridView where the user can add rows manually. The text for the button didn't appear and nothing seemed to work. I then remembered that there is always a NullValue property and after I set this, the text appeared on the button ;)

                          DataGridViewCellStyle8.NullValue = "Some Text"
                          Me.AddStillstand.DefaultCellStyle = DataGridViewCellStyle8
                          Me.AddStillstand.HeaderText = ""
                          Me.AddStillstand.Text = "Some Text"

                          Just in case someone else is having a similar issue ;)

                          B Offline
                          B Offline
                          Bob Stanneveld
                          wrote on last edited by
                          #16

                          Hi, I was pondering quite some time over this issue. The NullValue property did the trick :) Thanks for posting this! Kind regards, Bob Stanneveld

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups