datagridview button column - text not displaying [Solved]
-
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 = TrueThe 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:
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
-
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
-
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:
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
-
Simon_Whale wrote:
Runs with no errors but the text doesn't show up. Any ideas?
Yup, you set the
HeaderText
[^] property toNothing
. Try something like this;buttonColumn.HeaderText = "Hello World"
I are Troll :suss:
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
-
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
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:
-
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
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 pointThe 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 -
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 pointThe 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, DavidBelow 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
-
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
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. -
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.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 ;)
-
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
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
-
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
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.
-
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 ;)
Hi, I was pondering quite some time over this issue. The NullValue property did the trick :) Thanks for posting this! Kind regards, Bob Stanneveld