C
C#2y ago
Sal

Pass a value on a click event

hey, i am populating a stack panel with values from a data base, and i would like to have a button to select that value and at its right another to remove it from the database, but the button to remove doesnt have any context from the value i wanna remove, so how would i go about to using a single click event to all remove buttons but still know the Id related to the button i pressed?
9 Replies
Sal
Sal2y ago
i am thinking maybe i can name the button with the Id, that way i can have the name from the sender, is that a good solution?
Becquerel
Becquerel2y ago
how about when clicking the select buttons you add to a List<YourThing> of items to remove then when the delete button is clicked, it just looks at that list to get all the stuff to remove from the DB
Sal
Sal2y ago
that doesnt fit with what i wanna do, i don wanna select then delete multiple, i could do that but i just wanna have an option to delete near the name
Becquerel
Becquerel2y ago
why have separate buttons for selecting and deleting then
Sal
Sal2y ago
when i select i open maybe i said it wrong, just wanted to say click th name and open that click to the right where there is a "x" and delete
Becquerel
Becquerel2y ago
ohh ok how are you loading stuff into this stackpanel?
Sal
Sal2y ago
with a foreach DbSet<Models.PatchModel>? patches = context.Patches; iterate from this
Becquerel
Becquerel2y ago
i honestly forget how i used to do this in wpf i think i had a viewmodel specifically for each row of the panel so the item to operate on was obvious
Sal
Sal2y ago
i once did something similar where i had a grid with buttons and i could choose any but now i also forgot, either way in the mean while i manage to do by the name, just named the button with the ID of the item and i search the database for the Id and remove it