469,312 Members | 2,472 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

Change DataGridView Column Type

How to I changed bound column in DataGridView from DataGridViewTextBoxColumn(); to DataGridViewButtonColumn() ?

Thanks
Peter
Dec 2 '05 #1
4 27021
Hi Peter,

To use a DataGridViewButtonColumn, you just need to create such an object,
set its DataPropertyName property to the column name in the DataTable, and
then add the column to the DataGridView column collection. You can check
the following links for more information:

http://msdn2.microsoft.com/en-us/lib...datagridviewbu
ttoncolumn.aspx

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Dec 2 '05 #2

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:NW**************@TK2MSFTNGXA02.phx.gbl...
Hi Peter,

To use a DataGridViewButtonColumn, you just need to create such an object,
set its DataPropertyName property to the column name in the DataTable, and
then add the column to the DataGridView column collection. You can check
the following links for more information:

http://msdn2.microsoft.com/en-us/lib...datagridviewbu
ttoncolumn.aspx

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Thank you for you help!

The example shows me how to add a button column, but I don't want to add
extra column I want to convert existing column to a button after I bind it
with the dataset. How do I do that?
Dec 2 '05 #3
Hi Peter,

With the code I provided in my last post, we can add a column with buttons
to the DataGridView. Then we can check in the DataGridView.Columns to
remove the original column with textboxes.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Dec 3 '05 #4
Dear Kevin,

I did what you say but my new column has no values in its cells. It says is
databounded and the datapropertyname is right, but all cells are empty with a
value of Nothing...

I have:
myDGV.DataSource = my DataTable
'Since I want to change an existing column I call a sub as
ChangeToButton("MyColumn")

The ChangeToButton Sub is:
Private Sub ChangeToButtonColumn(ByVal strColumnName As String)
Dim buttons As New DataGridViewButtonColumn()
With buttons
.Name = strColumnName
.HeaderText = strColumnName
.DataPropertyName = strColumnName
'strColumnName is "MyColumn", which is a fields in MyTable the datasource
for MyDGV
.UseColumnTextForButtonValue = True
.FlatStyle = FlatStyle.Standard
.DisplayIndex = 6
End With
' I get rid of the original column
MyDGV.Columns.Remove(strColumnName)
'I add the new column
MyDGV.Columns.Add(buttons)
End Sub

Can you tell me what I am doing wrong?

Thank you

--
Sergio Torres C.
(505) 897 2041
___________________
http://www.stcsys.com
___________________

"Kevin Yu [MSFT]" wrote:
Hi Peter,

With the code I provided in my last post, we can add a column with buttons
to the DataGridView. Then we can check in the DataGridView.Columns to
remove the original column with textboxes.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Feb 2 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Dan Hartshorn | last post: by
3 posts views Thread by Alex Bibiano | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.