none
Datagridview Checkbox LINQ to SQL Question RRS feed

  • Question

  • Hi,

    I have a Datagridview that loads Items from my SQL database. These Items are created by users and will be placed in a table called Alias. I have a manager that will monitor the table called alias and if he approves of the Entry that entry will be deleted from that table and inserted into a Table called aliastoenter.

     

    My question: Using a Datagridview with a checkbox column, What LINQ code do I use (and How) to check the datagridview for Items checked and then delete those items from that table and insert them into the Aliastoenter table?

     

    Thanks.

    Wednesday, August 22, 2007 2:20 PM

Answers

  • Hi Lawrence,

     

    If your DataContext works in a connected manner you can have a look at to Linq data source control. It will do most of the work for you if you do the right configuration for it in the mark up.

     

    If you want to manipulate it yourself, you can of course.  I presume that you already associated that checkbox's column as a select button column and the selected rows' state is "selected" as it should be.

     

    Following code gets the entries those are selected in the data gridview

     

    Code Snippet

    var rowList = GridView1.Rows.OfType<GridViewRow>();

    IEnumerable entriesList = rowList.Where<GridViewRow>(gvr => gvr.RowState == DataControlRowState.Selected).Select<GridViewRow, Entry>(gv => gv.DataItem as Entry);

     

     

    You can then pass this entriesList to your table to be deleted with context by utilizing

     

    Code Snippet

    YourEntriesTable.AttachAllOnSubmit<Entry>(entriesList, true);

    YourEntriesTable.DeleteAllOnSubmit<Entry>(entriesList);

     

     

    Hope this is what you needed. (it might be a bit late though Smile)

     

    Sunday, May 18, 2008 12:52 PM

All replies

  • Lawrence,

    I found your question while scanning this forum for old unanswered questions. I am sorry to see that your question has gone unanswered for such a long time!

    To give it more chances, I will move it to the new LINQ to SQL forum, since the forum in which you originally posted it is currently focused on Entity Framework only.

    Thanks,
    Diego

    Sunday, May 18, 2008 10:29 AM
  • Hi Lawrence,

     

    If your DataContext works in a connected manner you can have a look at to Linq data source control. It will do most of the work for you if you do the right configuration for it in the mark up.

     

    If you want to manipulate it yourself, you can of course.  I presume that you already associated that checkbox's column as a select button column and the selected rows' state is "selected" as it should be.

     

    Following code gets the entries those are selected in the data gridview

     

    Code Snippet

    var rowList = GridView1.Rows.OfType<GridViewRow>();

    IEnumerable entriesList = rowList.Where<GridViewRow>(gvr => gvr.RowState == DataControlRowState.Selected).Select<GridViewRow, Entry>(gv => gv.DataItem as Entry);

     

     

    You can then pass this entriesList to your table to be deleted with context by utilizing

     

    Code Snippet

    YourEntriesTable.AttachAllOnSubmit<Entry>(entriesList, true);

    YourEntriesTable.DeleteAllOnSubmit<Entry>(entriesList);

     

     

    Hope this is what you needed. (it might be a bit late though Smile)

     

    Sunday, May 18, 2008 12:52 PM