Hello
i wanna make aList of ID from click on gridview devexpress row or cell
when i click save button
it's make forEach on This List and give me Alist Of item
for Example =>..
i want to click on this X button get me id of this row from dataBase and add it to Alist of IDS
how i can make it please ?!


Prasad RaveendranRank #320 · 7.8K reputationPosted Jul 4, 2024, 7:16 PM EDT
To achieve the desired functionality using DevExpress GridView, you can follow these steps:
Handle the Row/Cell Click Event to Capture the ID:
Handle the Save Button Click Event:
Here’s an example of how you can implement this in a Windows Forms application:
Step 1: Initialize the ListCreate a list to store the IDs globally within your form.
public partial class Form1 : Form { private List selectedIds = new List(); public Form1() { InitializeComponent(); // Initialize GridView and other components here } }Attach an event handler to the GridView’s click event to capture the ID and add it to the list.
private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) { int id = Convert.ToInt32(gridView1.GetRowCellValue(e.RowHandle, "ID")); // Assuming the column name is "ID" if (!selectedIds.Contains(id)) { selectedIds.Add(id); } }When the save button is clicked, iterate through the list of IDs and retrieve the items from the database.
private void btnSave_Click(object sender, EventArgs e) { List items = new List(); foreach (int id in selectedIds) { // Replace this with your actual data retrieval logic var item = GetItemFromDatabase(id); items.Add(item); } // Do something with the items list } private YourItemType GetItemFromDatabase(int id) { // Replace this with your actual data retrieval logic // Example: // return dbContext.YourItems.SingleOrDefault(item => item.ID == id); }Replace
YourItemTypeand theGetItemFromDatabasemethod with your actual data model and data retrieval logic. This example assumes that your data model has an ID column and that you have a method to retrieve items from the database by their ID.