How to check if multiple checkbox is selected or not in datagridview c#












0















I have a DataGridview where I can select multiple checkbox.but now I need to collected checked rows data and keep it. how can I check how many of my rows are selected and how can I keep me selected checkbox rows data.



I already did little code. but this only keep only one selected rows data.
Here is my code:



DataGridViewCell datacelll = dgvSlsSRsList.CurrentCell;

if (datacelll != null)
{
foreach (DataGridViewCheckBoxCell cell in dgvSlsSRsList.SelectedCells)
{
cell.Value = true;
slssrsId = Convert.ToInt32(dgvSlsSRsList.Rows[e.RowIndex].Cells[1].Value);
slssdpId = Convert.ToInt32(dgvSlsSRsList.Rows[e.RowIndex].Cells[2].Value);
DueAmount = Convert.ToDecimal(dgvSlsSRsList.Rows[e.RowIndex].Cells[8].Value);
}
dgvSlsSRsList.Refresh();
}









share|improve this question

























  • Why can't you loop through DataGridView ?

    – Midhun Mundayadan
    Jan 2 at 11:37






  • 1





    I would suggest you to bind your list as the Datatable.Datasource, then iterate on each row casting the "row.DataboundItem" in your model type. You'll then have just to check if your "rowObject" bool property is true.

    – Leogiciel
    Jan 2 at 11:45











  • I would go with @Leogiciel suggesting, bind a modelCollection to you gridView. And query your bound dataCollection with linq query to get the 'checked' data.

    – RazorShorts
    Jan 2 at 12:40
















0















I have a DataGridview where I can select multiple checkbox.but now I need to collected checked rows data and keep it. how can I check how many of my rows are selected and how can I keep me selected checkbox rows data.



I already did little code. but this only keep only one selected rows data.
Here is my code:



DataGridViewCell datacelll = dgvSlsSRsList.CurrentCell;

if (datacelll != null)
{
foreach (DataGridViewCheckBoxCell cell in dgvSlsSRsList.SelectedCells)
{
cell.Value = true;
slssrsId = Convert.ToInt32(dgvSlsSRsList.Rows[e.RowIndex].Cells[1].Value);
slssdpId = Convert.ToInt32(dgvSlsSRsList.Rows[e.RowIndex].Cells[2].Value);
DueAmount = Convert.ToDecimal(dgvSlsSRsList.Rows[e.RowIndex].Cells[8].Value);
}
dgvSlsSRsList.Refresh();
}









share|improve this question

























  • Why can't you loop through DataGridView ?

    – Midhun Mundayadan
    Jan 2 at 11:37






  • 1





    I would suggest you to bind your list as the Datatable.Datasource, then iterate on each row casting the "row.DataboundItem" in your model type. You'll then have just to check if your "rowObject" bool property is true.

    – Leogiciel
    Jan 2 at 11:45











  • I would go with @Leogiciel suggesting, bind a modelCollection to you gridView. And query your bound dataCollection with linq query to get the 'checked' data.

    – RazorShorts
    Jan 2 at 12:40














0












0








0








I have a DataGridview where I can select multiple checkbox.but now I need to collected checked rows data and keep it. how can I check how many of my rows are selected and how can I keep me selected checkbox rows data.



I already did little code. but this only keep only one selected rows data.
Here is my code:



DataGridViewCell datacelll = dgvSlsSRsList.CurrentCell;

if (datacelll != null)
{
foreach (DataGridViewCheckBoxCell cell in dgvSlsSRsList.SelectedCells)
{
cell.Value = true;
slssrsId = Convert.ToInt32(dgvSlsSRsList.Rows[e.RowIndex].Cells[1].Value);
slssdpId = Convert.ToInt32(dgvSlsSRsList.Rows[e.RowIndex].Cells[2].Value);
DueAmount = Convert.ToDecimal(dgvSlsSRsList.Rows[e.RowIndex].Cells[8].Value);
}
dgvSlsSRsList.Refresh();
}









share|improve this question
















I have a DataGridview where I can select multiple checkbox.but now I need to collected checked rows data and keep it. how can I check how many of my rows are selected and how can I keep me selected checkbox rows data.



I already did little code. but this only keep only one selected rows data.
Here is my code:



DataGridViewCell datacelll = dgvSlsSRsList.CurrentCell;

if (datacelll != null)
{
foreach (DataGridViewCheckBoxCell cell in dgvSlsSRsList.SelectedCells)
{
cell.Value = true;
slssrsId = Convert.ToInt32(dgvSlsSRsList.Rows[e.RowIndex].Cells[1].Value);
slssdpId = Convert.ToInt32(dgvSlsSRsList.Rows[e.RowIndex].Cells[2].Value);
DueAmount = Convert.ToDecimal(dgvSlsSRsList.Rows[e.RowIndex].Cells[8].Value);
}
dgvSlsSRsList.Refresh();
}






c# checkbox datagridview






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 11:34









R Pelzer

683825




683825










asked Jan 2 at 11:26









Ken KanekiKen Kaneki

55




55













  • Why can't you loop through DataGridView ?

    – Midhun Mundayadan
    Jan 2 at 11:37






  • 1





    I would suggest you to bind your list as the Datatable.Datasource, then iterate on each row casting the "row.DataboundItem" in your model type. You'll then have just to check if your "rowObject" bool property is true.

    – Leogiciel
    Jan 2 at 11:45











  • I would go with @Leogiciel suggesting, bind a modelCollection to you gridView. And query your bound dataCollection with linq query to get the 'checked' data.

    – RazorShorts
    Jan 2 at 12:40



















  • Why can't you loop through DataGridView ?

    – Midhun Mundayadan
    Jan 2 at 11:37






  • 1





    I would suggest you to bind your list as the Datatable.Datasource, then iterate on each row casting the "row.DataboundItem" in your model type. You'll then have just to check if your "rowObject" bool property is true.

    – Leogiciel
    Jan 2 at 11:45











  • I would go with @Leogiciel suggesting, bind a modelCollection to you gridView. And query your bound dataCollection with linq query to get the 'checked' data.

    – RazorShorts
    Jan 2 at 12:40

















Why can't you loop through DataGridView ?

– Midhun Mundayadan
Jan 2 at 11:37





Why can't you loop through DataGridView ?

– Midhun Mundayadan
Jan 2 at 11:37




1




1





I would suggest you to bind your list as the Datatable.Datasource, then iterate on each row casting the "row.DataboundItem" in your model type. You'll then have just to check if your "rowObject" bool property is true.

– Leogiciel
Jan 2 at 11:45





I would suggest you to bind your list as the Datatable.Datasource, then iterate on each row casting the "row.DataboundItem" in your model type. You'll then have just to check if your "rowObject" bool property is true.

– Leogiciel
Jan 2 at 11:45













I would go with @Leogiciel suggesting, bind a modelCollection to you gridView. And query your bound dataCollection with linq query to get the 'checked' data.

– RazorShorts
Jan 2 at 12:40





I would go with @Leogiciel suggesting, bind a modelCollection to you gridView. And query your bound dataCollection with linq query to get the 'checked' data.

– RazorShorts
Jan 2 at 12:40












1 Answer
1






active

oldest

votes


















0














ok. i get the solution from another post comment section.here is my solution-



                List<string> srlist = new List<string>();
List<string> sdplist = new List<string>();
List<string> dumamountlist = new List<string>();

foreach (DataGridViewRow row in this.dgvSlsSRsList.Rows)
{
var cell = row.Cells[e.ColumnIndex] as DataGridViewCheckBoxCell;

if (Convert.ToBoolean(cell.Value) == true)
{
srlist.Add(row.Cells[1].Value.ToString());
sdplist.Add(row.Cells[2].Value.ToString());
dumamountlist.Add(row.Cells[8].Value.ToString());


}
else if (cell.State == DataGridViewElementStates.Selected)
{
srlist.Add(row.Cells[1].Value.ToString());
sdplist.Add(row.Cells[2].Value.ToString());
dumamountlist.Add(row.Cells[8].Value.ToString());
}

}





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54005495%2fhow-to-check-if-multiple-checkbox-is-selected-or-not-in-datagridview-c-sharp%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    ok. i get the solution from another post comment section.here is my solution-



                    List<string> srlist = new List<string>();
    List<string> sdplist = new List<string>();
    List<string> dumamountlist = new List<string>();

    foreach (DataGridViewRow row in this.dgvSlsSRsList.Rows)
    {
    var cell = row.Cells[e.ColumnIndex] as DataGridViewCheckBoxCell;

    if (Convert.ToBoolean(cell.Value) == true)
    {
    srlist.Add(row.Cells[1].Value.ToString());
    sdplist.Add(row.Cells[2].Value.ToString());
    dumamountlist.Add(row.Cells[8].Value.ToString());


    }
    else if (cell.State == DataGridViewElementStates.Selected)
    {
    srlist.Add(row.Cells[1].Value.ToString());
    sdplist.Add(row.Cells[2].Value.ToString());
    dumamountlist.Add(row.Cells[8].Value.ToString());
    }

    }





    share|improve this answer




























      0














      ok. i get the solution from another post comment section.here is my solution-



                      List<string> srlist = new List<string>();
      List<string> sdplist = new List<string>();
      List<string> dumamountlist = new List<string>();

      foreach (DataGridViewRow row in this.dgvSlsSRsList.Rows)
      {
      var cell = row.Cells[e.ColumnIndex] as DataGridViewCheckBoxCell;

      if (Convert.ToBoolean(cell.Value) == true)
      {
      srlist.Add(row.Cells[1].Value.ToString());
      sdplist.Add(row.Cells[2].Value.ToString());
      dumamountlist.Add(row.Cells[8].Value.ToString());


      }
      else if (cell.State == DataGridViewElementStates.Selected)
      {
      srlist.Add(row.Cells[1].Value.ToString());
      sdplist.Add(row.Cells[2].Value.ToString());
      dumamountlist.Add(row.Cells[8].Value.ToString());
      }

      }





      share|improve this answer


























        0












        0








        0







        ok. i get the solution from another post comment section.here is my solution-



                        List<string> srlist = new List<string>();
        List<string> sdplist = new List<string>();
        List<string> dumamountlist = new List<string>();

        foreach (DataGridViewRow row in this.dgvSlsSRsList.Rows)
        {
        var cell = row.Cells[e.ColumnIndex] as DataGridViewCheckBoxCell;

        if (Convert.ToBoolean(cell.Value) == true)
        {
        srlist.Add(row.Cells[1].Value.ToString());
        sdplist.Add(row.Cells[2].Value.ToString());
        dumamountlist.Add(row.Cells[8].Value.ToString());


        }
        else if (cell.State == DataGridViewElementStates.Selected)
        {
        srlist.Add(row.Cells[1].Value.ToString());
        sdplist.Add(row.Cells[2].Value.ToString());
        dumamountlist.Add(row.Cells[8].Value.ToString());
        }

        }





        share|improve this answer













        ok. i get the solution from another post comment section.here is my solution-



                        List<string> srlist = new List<string>();
        List<string> sdplist = new List<string>();
        List<string> dumamountlist = new List<string>();

        foreach (DataGridViewRow row in this.dgvSlsSRsList.Rows)
        {
        var cell = row.Cells[e.ColumnIndex] as DataGridViewCheckBoxCell;

        if (Convert.ToBoolean(cell.Value) == true)
        {
        srlist.Add(row.Cells[1].Value.ToString());
        sdplist.Add(row.Cells[2].Value.ToString());
        dumamountlist.Add(row.Cells[8].Value.ToString());


        }
        else if (cell.State == DataGridViewElementStates.Selected)
        {
        srlist.Add(row.Cells[1].Value.ToString());
        sdplist.Add(row.Cells[2].Value.ToString());
        dumamountlist.Add(row.Cells[8].Value.ToString());
        }

        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 2 at 12:43









        Ken KanekiKen Kaneki

        55




        55
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54005495%2fhow-to-check-if-multiple-checkbox-is-selected-or-not-in-datagridview-c-sharp%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas

            Can't read property showImagePicker of undefined in react native iOS