Display Datagridview dynamically created chechboxvalue? c#












0














I want to check all/ only certain Checkboxes as checked.
I tried various versions from stackoverflow but none seem to work out.
The code is called directly after dynamically creating the datagrid as I only want to load the Data once. - Datagrid is created in my Form_Load
The value of the Checkboxes are changed but not displayed.



//This is how i create the Datagrid column - not question relevant



for (int kacnt = 1; kacnt <= Ei.Kaanzahl; kacnt++)
{
DataGridViewCheckBoxColumn Kachk = new DataGridViewCheckBoxColumn();
Kachk.HeaderText = "Kamera" + kacnt;
Kachk.Width = 70;
WarDataGridView.Columns.Add(Kachk);
}


// The code I actually have problems with - the display of the value



       foreach (DataGridViewRow row in WarDataGridView.Rows)
{
for (int col = 1; col < WarDataGridView.ColumnCount; col++)
{
(WarDataGridView.Rows[row.Index].Cells[col] as DataGridViewCheckBoxCell).Value = true;}}









share|improve this question
























  • It's unclear what you are asking. Please consider posting a Minimal, Complete, and Verifiable example to reproduce the problem and describe the problem and expected result.
    – Reza Aghaei
    Dec 27 '18 at 15:06










  • Can you also mention event or method, in which you are trying to update DataGridView source? You will need to refresh once datagridview source is being updated.. try following stackoverflow discussion,, stackoverflow.com/questions/7008361/…
    – Hitesh Gaur
    Dec 27 '18 at 15:26










  • What is the column index of the column you want to check? You are starting at index 1 which means you are skipping the first column (index 0). Also, if your checkbox column is hidden, you need to use WarDataGridView.Columns.Count in your for loop. WarDataGridView.ColumnCount only returns displayed columns.
    – Smitty-Werben-Jager-Manjenson
    Dec 27 '18 at 15:33










  • Edited the above things.. I only want to check displayed columns and yes i am skipping the first column intentionally since it is a Text Column.. Thanks a lot tho
    – JayJay
    Dec 27 '18 at 15:36












  • Are you using a datasource, i.e. WarDataGridView.DataSource = dataSource_dataTable? I've noticed the data isn't finished loading immediately after databinding. In that case you need a WarDataGridView.DataBindingComplete event, and set the columns from there. You also may need to set the particular column with Kamerachk.TrueValue = true and Kamerachk .FalseValue = false
    – Smitty-Werben-Jager-Manjenson
    Dec 27 '18 at 15:42
















0














I want to check all/ only certain Checkboxes as checked.
I tried various versions from stackoverflow but none seem to work out.
The code is called directly after dynamically creating the datagrid as I only want to load the Data once. - Datagrid is created in my Form_Load
The value of the Checkboxes are changed but not displayed.



//This is how i create the Datagrid column - not question relevant



for (int kacnt = 1; kacnt <= Ei.Kaanzahl; kacnt++)
{
DataGridViewCheckBoxColumn Kachk = new DataGridViewCheckBoxColumn();
Kachk.HeaderText = "Kamera" + kacnt;
Kachk.Width = 70;
WarDataGridView.Columns.Add(Kachk);
}


// The code I actually have problems with - the display of the value



       foreach (DataGridViewRow row in WarDataGridView.Rows)
{
for (int col = 1; col < WarDataGridView.ColumnCount; col++)
{
(WarDataGridView.Rows[row.Index].Cells[col] as DataGridViewCheckBoxCell).Value = true;}}









share|improve this question
























  • It's unclear what you are asking. Please consider posting a Minimal, Complete, and Verifiable example to reproduce the problem and describe the problem and expected result.
    – Reza Aghaei
    Dec 27 '18 at 15:06










  • Can you also mention event or method, in which you are trying to update DataGridView source? You will need to refresh once datagridview source is being updated.. try following stackoverflow discussion,, stackoverflow.com/questions/7008361/…
    – Hitesh Gaur
    Dec 27 '18 at 15:26










  • What is the column index of the column you want to check? You are starting at index 1 which means you are skipping the first column (index 0). Also, if your checkbox column is hidden, you need to use WarDataGridView.Columns.Count in your for loop. WarDataGridView.ColumnCount only returns displayed columns.
    – Smitty-Werben-Jager-Manjenson
    Dec 27 '18 at 15:33










  • Edited the above things.. I only want to check displayed columns and yes i am skipping the first column intentionally since it is a Text Column.. Thanks a lot tho
    – JayJay
    Dec 27 '18 at 15:36












  • Are you using a datasource, i.e. WarDataGridView.DataSource = dataSource_dataTable? I've noticed the data isn't finished loading immediately after databinding. In that case you need a WarDataGridView.DataBindingComplete event, and set the columns from there. You also may need to set the particular column with Kamerachk.TrueValue = true and Kamerachk .FalseValue = false
    – Smitty-Werben-Jager-Manjenson
    Dec 27 '18 at 15:42














0












0








0







I want to check all/ only certain Checkboxes as checked.
I tried various versions from stackoverflow but none seem to work out.
The code is called directly after dynamically creating the datagrid as I only want to load the Data once. - Datagrid is created in my Form_Load
The value of the Checkboxes are changed but not displayed.



//This is how i create the Datagrid column - not question relevant



for (int kacnt = 1; kacnt <= Ei.Kaanzahl; kacnt++)
{
DataGridViewCheckBoxColumn Kachk = new DataGridViewCheckBoxColumn();
Kachk.HeaderText = "Kamera" + kacnt;
Kachk.Width = 70;
WarDataGridView.Columns.Add(Kachk);
}


// The code I actually have problems with - the display of the value



       foreach (DataGridViewRow row in WarDataGridView.Rows)
{
for (int col = 1; col < WarDataGridView.ColumnCount; col++)
{
(WarDataGridView.Rows[row.Index].Cells[col] as DataGridViewCheckBoxCell).Value = true;}}









share|improve this question















I want to check all/ only certain Checkboxes as checked.
I tried various versions from stackoverflow but none seem to work out.
The code is called directly after dynamically creating the datagrid as I only want to load the Data once. - Datagrid is created in my Form_Load
The value of the Checkboxes are changed but not displayed.



//This is how i create the Datagrid column - not question relevant



for (int kacnt = 1; kacnt <= Ei.Kaanzahl; kacnt++)
{
DataGridViewCheckBoxColumn Kachk = new DataGridViewCheckBoxColumn();
Kachk.HeaderText = "Kamera" + kacnt;
Kachk.Width = 70;
WarDataGridView.Columns.Add(Kachk);
}


// The code I actually have problems with - the display of the value



       foreach (DataGridViewRow row in WarDataGridView.Rows)
{
for (int col = 1; col < WarDataGridView.ColumnCount; col++)
{
(WarDataGridView.Rows[row.Index].Cells[col] as DataGridViewCheckBoxCell).Value = true;}}






c# winforms checkbox datagridviewcolumn






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 27 '18 at 16:00

























asked Dec 27 '18 at 15:02









JayJay

154




154












  • It's unclear what you are asking. Please consider posting a Minimal, Complete, and Verifiable example to reproduce the problem and describe the problem and expected result.
    – Reza Aghaei
    Dec 27 '18 at 15:06










  • Can you also mention event or method, in which you are trying to update DataGridView source? You will need to refresh once datagridview source is being updated.. try following stackoverflow discussion,, stackoverflow.com/questions/7008361/…
    – Hitesh Gaur
    Dec 27 '18 at 15:26










  • What is the column index of the column you want to check? You are starting at index 1 which means you are skipping the first column (index 0). Also, if your checkbox column is hidden, you need to use WarDataGridView.Columns.Count in your for loop. WarDataGridView.ColumnCount only returns displayed columns.
    – Smitty-Werben-Jager-Manjenson
    Dec 27 '18 at 15:33










  • Edited the above things.. I only want to check displayed columns and yes i am skipping the first column intentionally since it is a Text Column.. Thanks a lot tho
    – JayJay
    Dec 27 '18 at 15:36












  • Are you using a datasource, i.e. WarDataGridView.DataSource = dataSource_dataTable? I've noticed the data isn't finished loading immediately after databinding. In that case you need a WarDataGridView.DataBindingComplete event, and set the columns from there. You also may need to set the particular column with Kamerachk.TrueValue = true and Kamerachk .FalseValue = false
    – Smitty-Werben-Jager-Manjenson
    Dec 27 '18 at 15:42


















  • It's unclear what you are asking. Please consider posting a Minimal, Complete, and Verifiable example to reproduce the problem and describe the problem and expected result.
    – Reza Aghaei
    Dec 27 '18 at 15:06










  • Can you also mention event or method, in which you are trying to update DataGridView source? You will need to refresh once datagridview source is being updated.. try following stackoverflow discussion,, stackoverflow.com/questions/7008361/…
    – Hitesh Gaur
    Dec 27 '18 at 15:26










  • What is the column index of the column you want to check? You are starting at index 1 which means you are skipping the first column (index 0). Also, if your checkbox column is hidden, you need to use WarDataGridView.Columns.Count in your for loop. WarDataGridView.ColumnCount only returns displayed columns.
    – Smitty-Werben-Jager-Manjenson
    Dec 27 '18 at 15:33










  • Edited the above things.. I only want to check displayed columns and yes i am skipping the first column intentionally since it is a Text Column.. Thanks a lot tho
    – JayJay
    Dec 27 '18 at 15:36












  • Are you using a datasource, i.e. WarDataGridView.DataSource = dataSource_dataTable? I've noticed the data isn't finished loading immediately after databinding. In that case you need a WarDataGridView.DataBindingComplete event, and set the columns from there. You also may need to set the particular column with Kamerachk.TrueValue = true and Kamerachk .FalseValue = false
    – Smitty-Werben-Jager-Manjenson
    Dec 27 '18 at 15:42
















It's unclear what you are asking. Please consider posting a Minimal, Complete, and Verifiable example to reproduce the problem and describe the problem and expected result.
– Reza Aghaei
Dec 27 '18 at 15:06




It's unclear what you are asking. Please consider posting a Minimal, Complete, and Verifiable example to reproduce the problem and describe the problem and expected result.
– Reza Aghaei
Dec 27 '18 at 15:06












Can you also mention event or method, in which you are trying to update DataGridView source? You will need to refresh once datagridview source is being updated.. try following stackoverflow discussion,, stackoverflow.com/questions/7008361/…
– Hitesh Gaur
Dec 27 '18 at 15:26




Can you also mention event or method, in which you are trying to update DataGridView source? You will need to refresh once datagridview source is being updated.. try following stackoverflow discussion,, stackoverflow.com/questions/7008361/…
– Hitesh Gaur
Dec 27 '18 at 15:26












What is the column index of the column you want to check? You are starting at index 1 which means you are skipping the first column (index 0). Also, if your checkbox column is hidden, you need to use WarDataGridView.Columns.Count in your for loop. WarDataGridView.ColumnCount only returns displayed columns.
– Smitty-Werben-Jager-Manjenson
Dec 27 '18 at 15:33




What is the column index of the column you want to check? You are starting at index 1 which means you are skipping the first column (index 0). Also, if your checkbox column is hidden, you need to use WarDataGridView.Columns.Count in your for loop. WarDataGridView.ColumnCount only returns displayed columns.
– Smitty-Werben-Jager-Manjenson
Dec 27 '18 at 15:33












Edited the above things.. I only want to check displayed columns and yes i am skipping the first column intentionally since it is a Text Column.. Thanks a lot tho
– JayJay
Dec 27 '18 at 15:36






Edited the above things.. I only want to check displayed columns and yes i am skipping the first column intentionally since it is a Text Column.. Thanks a lot tho
– JayJay
Dec 27 '18 at 15:36














Are you using a datasource, i.e. WarDataGridView.DataSource = dataSource_dataTable? I've noticed the data isn't finished loading immediately after databinding. In that case you need a WarDataGridView.DataBindingComplete event, and set the columns from there. You also may need to set the particular column with Kamerachk.TrueValue = true and Kamerachk .FalseValue = false
– Smitty-Werben-Jager-Manjenson
Dec 27 '18 at 15:42




Are you using a datasource, i.e. WarDataGridView.DataSource = dataSource_dataTable? I've noticed the data isn't finished loading immediately after databinding. In that case you need a WarDataGridView.DataBindingComplete event, and set the columns from there. You also may need to set the particular column with Kamerachk.TrueValue = true and Kamerachk .FalseValue = false
– Smitty-Werben-Jager-Manjenson
Dec 27 '18 at 15:42












1 Answer
1






active

oldest

votes


















1














Set your columns' True and False values like so:



Kamerachk.TrueValue = true;
and
Kamerachk.TrueValue = false;






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%2f53947046%2fdisplay-datagridview-dynamically-created-chechboxvalue-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









    1














    Set your columns' True and False values like so:



    Kamerachk.TrueValue = true;
    and
    Kamerachk.TrueValue = false;






    share|improve this answer


























      1














      Set your columns' True and False values like so:



      Kamerachk.TrueValue = true;
      and
      Kamerachk.TrueValue = false;






      share|improve this answer
























        1












        1








        1






        Set your columns' True and False values like so:



        Kamerachk.TrueValue = true;
        and
        Kamerachk.TrueValue = false;






        share|improve this answer












        Set your columns' True and False values like so:



        Kamerachk.TrueValue = true;
        and
        Kamerachk.TrueValue = false;







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 27 '18 at 15:57









        Smitty-Werben-Jager-Manjenson

        1109




        1109






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53947046%2fdisplay-datagridview-dynamically-created-chechboxvalue-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

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas