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. :)
 
sorry sorry, single button in specific cell.
Are you really sure about that? What's the actual workflow here? It seems to me that your grid contains a list of items for purchase and each time an item is selected it's added to the list. Presumably each item in the list should have its own button and clicking that button removes that item from the list, right? If you had 10 items in the list, surely you'd have 10 buttons all in the same column, one per row, right?

EDIT: Post #15 pretty much confirms what I'm saying. You have two items in the list and both have a button and both buttons are in the same column, so it's not just one button in one specific cell, is it?
 
Im sorry. -.- yea not just one button. One button per product that I add in the cart.


fvwvwi.png


2e54mdg.png
 
Im sorry. -.- yea not just one button. One button per product that I add in the cart.

In that case that code example from post #2 is irrelevant because that was for a single cell. As I have already said, you simply add a button column to the grid and then a button will be displayed in that column automatically fro each row you add. You can add the column in the designer or in code; it matters not. As I have also said, you handle the CellContentClick event of the grid and get the column and/or row index of the cell whose content was clicked from the `e` parameter, then use them as required. If you want to remove the current row then you've got the index of that row so go ahead and remove it.
 
Look what I did, it's stil not werking. -.-
25ktwkw.png
Perhaps if you were to explain what the code is supposed then it might be clear why it's not doing it. Regardless of that, why are you looping through the entire grid? Surely all you're interested in is the row containing the button that was just clicked.
 
so remove the loop ? only the if statements ? still not working if i remove the loop.

Then you did it wrong. As you STILL have not provided a CLEAR explanation of EXACTLY what you want the code to do, you're still just wasting my time. Stop expecting people to read your mind.
 
If I click the button of cooler master cosmos in gridview then

c7xms.png
<------------1.This button "add to cart " will enabled = true because if I click that add to cart button there's a code enabled = false, so that,It can't double product in the cart.2.Removing row 3.There will be picturebox1.visible = true if user click the "add to cart" button. then if I click the button on gridview for cooler master cosmos the picturebox1.visible = false.

You want me to send you my project ?
 
Back
Top