I'm a beginner of C# users.
I'm using the DevExpress with C# Window Form Application.
I'm trying to move row from gridcontrol_1 to gridcontrol_2.
The gridcontrol_1 connected from sql server DB TableA. i using (LINQ)
If I clicked on items from gridcontrol_1 then move to gridcontrol_2 by and remove from gridcontrol_1
If I deselect items from gridcontrol_2 then move back to gridcontrol_1 by click event.
Finally, I want to save(insert) the gridcontrol_2 items to the SQL server TableB. using (LINQ)
I don't know how to code what I want.
I found a video clip from youtube similarly I want to do.
But, the clip shows only DataGridView Control, not GridControl.
and how i save gridControl2 to DB by LINQ

Nikunj SatasiyaRank #302 · 8.3K reputationPosted Jul 10, 2024, 9:03 PM EDT
Hi Mohamed,
I assumes that you have already set up your DevExpress GridControls (
gridControl_1andgridControl_2) and LINQ DataContext (dbContext):I writing a sample code for you, you can take refrence from it.
// Move selected rows from gridControl_1 to gridControl_2 private void MoveToGridControl2() { foreach (int rowHandle in gridView1.GetSelectedRows()) { DataRow row = gridView1.GetDataRow(rowHandle); // Add row to gridControl_2 gridView2.AddNewRow(); int newRowHandle = gridView2.GetDataSourceRowIndex(gridView2.DataRowCount); gridView2.SetRowCellValue(newRowHandle, "Column1", row["Column1"]); // Adjust column name as per your data structure // Remove row from gridControl_1 gridView1.DeleteRow(rowHandle); } } // Move selected rows from gridControl_2 to gridControl_1 private void MoveToGridControl1() { foreach (int rowHandle in gridView2.GetSelectedRows()) { DataRow row = gridView2.GetDataRow(rowHandle); // Add row to gridControl_1 gridView1.AddNewRow(); int newRowHandle = gridView1.GetDataSourceRowIndex(gridView1.DataRowCount); gridView1.SetRowCellValue(newRowHandle, "Column1", row["Column1"]); // Adjust column name as per your data structure // Remove row from gridControl_2 gridView2.DeleteRow(rowHandle); } } // Save data from gridControl_2 to TableB using LINQ private void SaveToTableB() { foreach (int rowHandle in gridView2.GetSelectedRows()) { DataRow row = gridView2.GetDataRow(rowHandle); // Extract data from gridControl_2 row and save to TableB using LINQ TableB newRecord = new TableB { Column1 = row["Column1"].ToString(), // Adjust column name and type as per your TableB structure // Map other columns accordingly }; dbContext.TableBs.InsertOnSubmit(newRecord); } dbContext.SubmitChanges(); // Save changes to database }Please make sure that you have set up proper data bindings and column mappings in your GridControls as well as Replace "Column1" with actual column names from your database and adjust data types as necessary.
MohamedEid102 reputationPosted Jul 12, 2024, 11:09 AM EDT
DataRow row = gridView1.GetDataRow(rowHandle); => this row return null
this is datasource for gridControl1
var db = new DAL.DBDataContext();
gridControl1.DataSource = db.analysisPickTbls.ToList();
how i run this code please ?!!