0

i am programming a piece of software for a loyalty scheme. I have basically finished all of it. The only thing i am stuck on for ages is programming the buttons for the datagridview which i am using for my redeem offers page. I have gotten it to add a button to the end of each row automatically when you add a new offer but i am clueless on how to program it to recognize each row.

for e.g.) Row1) Offer 1 is X name and costs Y Row2) offer 2 is Z Name and costs F

I can only seem to find the ability to program every single button at once and not individual and even so, i need it to work automatically so when i can add a offer i can immediately purchase it. How would i get it to recognize which row i am on? here is what my form and database looks like. Picture Of Form - (picture link)

What my database looks like - (picture link)

2

3 Answers 3

2

below ur class

make public int id;

//adding button

 DataGridViewButtonColumn col = new DataGridViewButtonColumn();
    col.UseColumnTextForButtonValue = True;
    col.Text = "ADD";
    col.Name = "Btn_add";
    DataGridView1.Columns.Add(col);

//pass id values here to do functions..

private void Btn_add_Click(object sender, EventArgs e)
    {

   }

//this gets selected index of selected row value

private void DataGridView1_SelectionChanged(object sender, EventArgs e) {

     int id =  DataGridView1.SelectedRows(0).Cells(0).Value;

}

Sign up to request clarification or add additional context in comments.

11 Comments

Hey, what would i call the value for yourdatagridname int id = yourdatagridname.SelectedRows(0).Cells(0).Value; my datagrid is called DataGridView1 but its not recognized
I did, but now i am receiving an error to say i cant use 'SelectedRows' as a method anymore. i right clicked my datagrid view and copied the name 'offersDataGridView' to it and it is recognizing it now but it says i cant use selectedrows.
Please give me 15 minutes, i am on a break now. I will be back at the computer then. Please check back in 15 mins i appreciate it
where does the code for add button go? on form load?
I have gotten it to almost work. Now it just says the 'Cells' part is a error with no possible fixes given.
|
0

In Datagrid please bind OfferId in buy button. When press button then automatically gives id onclick event.

1 Comment

fam, how i cant figure it out
0

You can simply hook into the RowDataBound Event. This event is called, each time a new entry is put into the table. At this point, you can add a button to the tabe and add a custom action/url to the url.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.