Question How to use button inside of datagridview

Crincee

Member
Joined
Sep 21, 2014
Messages
15
Programming Experience
1-3
I need some help,I want first to add button on datagrid by clicking button on other form, then putting a code inside of the button ? I just need on my system for our school. :)
 
If you want a column of buttons in a DataGridView then add a button column to the grid. Each row will then display a button in that column. If you want a button just in a specific cell then you create an DataGridViewButtonCell and put it at the desired location, e.g.
myDataGridView(columnIndex, rowIndex) = New DataGridViewButtonCell
You can handle the CellContentClick event of the grid, which will be raised whenever the user clicks a button in a cell. You use the `e` parameter to determine what cell the button was in and then act accordingly.
 
Yo ! buddy, thnx for the reply.look how I add a button in datagridview.
when I click a button from other. then it will add a button on datagridview from other form also.My problem is,putting a codes inside of that button in the datagridview. Removing row,button1.enabled = true etc. I just really need on my system. :D
2hnt4k4.png
 
Its so confusing,because I have form per product, so I will add product on cart randomly,and what i want to happen is, to have a remove button on gridview,and every button per product is containing different code, like product1btn_gridview(button1.enabled = true),product2btn_gridview(button2.enabled = true) like that. sorry its so hard to explain. -.-
Cart:
vmy9at.png

ProductDetails
dg76z4.png
 
every button per product is containing different code

No it won't. It's not confusing if you actually read what I post and follow the instructions provided. There is no code in any button. There is ONE event handler: for the CellContentClick event of the grid. That's it, that's all. Whenever the user clicks a button in the grid, that event is raised. In the event handler you get the index of the row the button is in. If you have the row index then you can get the row. You then do whatever needs to be done with that row. Stopp assuming it's hard and just do as instructed. Where's your CellContentClick event handler? Until I see that I will not be spending any more time on this.
 
Do I still need this ? Im sorry, Im not really familiar in datagridview. but I will try to do what you say. thnx by the way
Dim objButtonColumn = New DataGridViewButtonColumn objButtonColumn.HeaderText = ""
objButtonColumn.Name = "EditColumn"
objButtonColumn.Text = "Remove"
Cart.DataGridView1.Columns.Add(objButtonColumn)
 
It would help if you actually read what was being posted. In post #2 I gave you a choice. Do you want a column of buttons or just a single button in a specific cell?
 
myDataGridView(columnIndex, rowIndex) = New DataGridViewButtonCell , I will put it in ADD TO CART button ? on my product form ?
buddy please, provide some sample code that i will put in gridview. I already search a lot about this kind of problem -.-
 
I asked you a question.
It would help if you actually read what was being posted. In post #2 I gave you a choice. Do you want a column of buttons or just a single button in a specific cell?
If I ask a question I'm asking it for a reason.
 
-.-
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
DataGridView1.Rows.RemoveAt(e.RowIndex)
CoolCos.btn_cosmos.Enabled = True
End Sub



2vm9bwx.png
 
Back
Top