SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2006
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DataGridView Checkbox

    Hi,

    I have a Checkbox column in the DataGridView.

    I am unable to change the state of the checkbox.

    Why is this??? What do I need to set in Properties?

    Using Visual Studio 2005

    Thanks.

  2. #2
    SitePoint Wizard
    Join Date
    Feb 2007
    Posts
    1,274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are probably databinding unconditonally on every Page_Load. If so, guard the databinding with an If (!IsPostBack) { ... }

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2006
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am building a Windows Application - not a webpage.

    Can I still use Postback??

    How should I set the databinding?

    Thanks.

  4. #4
    SitePoint Evangelist
    Join Date
    Oct 2006
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK I am able to Check/Uncheck an unbound DGV CheckBox. Set Read-Only to false.

    I want to bind the primary key of my table to the checkbox.
    If I do this then I am unable to check/uncheck the checkbox.

    Any ideas?

    Thanks

  5. #5
    SitePoint Evangelist
    Join Date
    Oct 2006
    Posts
    408
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This code works for me provided the user only checks the checkbox once...

    How Do I ensure the ArrayList only adds when the checkbox is at checked state??

    Thanks!!

    Code:
    private void counterPartyDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
                DataGridView dgv2 = sender as DataGridView;
    
                if ((e.RowIndex != -1) && (e.ColumnIndex != -1))
                {
                    ArrayList mySelectionArray = new ArrayList();
    
                    if (e.ColumnIndex == 0)
                    {
                        DataRow dr2 = ((DataRowView)dgv2.Rows[e.RowIndex].DataBoundItem).Row;
    
                        int mySelection2 = (int)dr2[dgv2.Columns[1].DataPropertyName]; // 1 = unique id column
                        mySelectionArray.Add(mySelection2);
                    }
                }
            }

  6. #6
    SitePoint Member xela220's Avatar
    Join Date
    Oct 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by k09 View Post
    OK I am able to Check/Uncheck an unbound DGV CheckBox. Set Read-Only to false.

    I want to bind the primary key of my table to the checkbox.
    If I do this then I am unable to check/uncheck the checkbox.

    Any ideas?

    Thanks
    Checkboxes indicate true or false (boolean). Do you have a primary key using boolean data type?

    Windows forms are statefull and, hence, they do not have a post back. Once the forms loads you have all the objects available until you dispose of them.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •