Solved

problem setting a check box from cell leave

Posted on 2011-09-30
7
258 Views
Last Modified: 2012-05-12
I am trying to set a check box value within a Data grid cell leave
event.  
Here is what I have coded, but it isn't working:
     void dgvPatientstoReview_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == -1) return;

           
            if (this.dgvPatientstoReview.Columns[e.ColumnIndex].Name == this.CreateAdj.Name)
            {
               
                DataRowView rowView = (DataRowView)this.m_srcBillingAudit.Current;
                string checkbox = this.dgvPatientstoReview.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue.ToString();
               
                if (checkbox.Equals("True".ToString()))
                {
                    if (string.IsNullOrEmpty(rowView["ClearReason"].ToString()))
                    {
                        MessageBox.Show("You must supply a reason in order to make an adjustment");
                        dgvPatientstoReview.Rows[e.RowIndex].Cells["CreateAdj"].Selected = false;
                        //((DataGridViewCheckBoxCell)dgvPatientstoReview.Rows[e.RowIndex].Cells["CreateAdj"]).Selected = false;
                        //((DataGridViewCheckBoxCell_dgvPatientstoReview.Rows[e.RowIndex].Cells[e.ColumnIndex]).Selected = false;
0
Comment
Question by:LenTompkins
  • 4
  • 3
7 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36893455
What if we try changing this:

if (checkbox.Equals("True".ToString()))

Open in new window


to this:

if (checkbox.Equals(bool.TrueString, StringComparison.InvariantCultureIgnoreCase))

Open in new window

0
 

Author Comment

by:LenTompkins
ID: 36893676
The test to look at checkbox = true works fine, when the user has not already submitted a reason
in ClearReason, I am trying to reset the check box back to false or not selected along with the
message.  That is what is not working.
Any thoughts?
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 36894118
I believe this is what you are referring to. It's not specific to your code above, but hopefully it demonstrates what I think you are asking. Let me know otherwise  = )
private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e)
{
    DataGridView dgv = sender as DataGridView;

    if (dgv != null && dgv[e.ColumnIndex, e.RowIndex] is DataGridViewCheckBoxCell)
    {
        DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)dgv[e.ColumnIndex, e.RowIndex];

        cell.Value = false;
    }
}

Open in new window

0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:LenTompkins
ID: 36894379
Sorry it did not work either.  This grid contains two check boxes that are next to each other.  It made
me think that the next box which is not checked is getting the false value, but I just did another
test where both boxes are checked and it did not change the result of either one. Could the problem
be that this check box is not associated with a column in my table?  I'm going to try this next by adding
a column to the table and see if that changes the check box to false.  If you have any other ideas
on how to solve this, I'd like to hear.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 36894982
Can you provide a screenshot of the form? Specifically, the check box area?
0
 

Author Comment

by:LenTompkins
ID: 36903293
Sorry I didn't respond over the weekend.  I tried a completely different way to solve this, and that
was worse, so here is a recap of the problem:
This is the screen print when I come into the form:
 
I also included the CellLeave code a
 Thank you , this has been driving me crazy.

 

Here is the code :
void dgvPatientstoReview_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == -1) return;

           
            if (this.dgvPatientstoReview.Columns[e.ColumnIndex].Name == this.CreateAdj.Name)
            {
               
                DataRowView rowView = (DataRowView)this.m_srcBillingAudit.Current;
                string checkbox = this.dgvPatientstoReview.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue.ToString();
               
                if (checkbox.Equals("True".ToString()))
                {
                    if (dgvPatientstoReview != null && dgvPatientstoReview[e.ColumnIndex, e.RowIndex] is DataGridViewCheckBoxCell)
                    {
                        DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)dgvPatientstoReview[e.ColumnIndex, e.RowIndex];

                        cell.Value = false;
                    }


                    if (string.IsNullOrEmpty(rowView["ClearReason"].ToString()))
                        MessageBox.Show("You must supply a reason in order to make an adjustment");

                    else
                    {
                        string differ = rowView["diff"].ToString();
                       
                        DialogResult result1 = MessageBox.Show(string.Format("An Adjustment of {0} days at Patient will be made.  Are you sure you want to do this? ",
                          differ), "Confirm Making Adjustments",
                          MessageBoxButtons.YesNo);
                        if (result1 == DialogResult.Yes)
                        {
                            m_BillingAdj.InsertBillingAuditAdjustment(rowView["MRN"].ToString(),
                                Convert.ToInt32(rowView["NO"].ToString()), Convert.ToInt32(differ), rowView["ClearReason"].ToString());
                            m_dtBillingAdj = m_BillingAdj.SelectBillingAuditAdjustments(rowView["MRN"].ToString(),
                                 Convert.ToInt32(rowView["NO"].ToString()));
                            m_srcBillingAdj.DataSource = m_dtBillingAdj;
                            dgvBillingAdjustments.DataSource = m_srcBillingAdj;
                            // update the BillingAudit table but we will not reselect records since that will clear this
                            // record and the user will not be able to review this change.
                            string delflag = this.dgvPatientstoReview.Rows[e.RowIndex].Cells["CPRFixed"].EditedFormattedValue.ToString();
                            if (delflag.Equals("True".ToString()))
                                cprFix = 1;
                            else
                                cprFix = 0;
                            int newDays = Convert.ToInt32(rowView["DaysAtPatient"].ToString()) + Convert.ToInt32(differ);
                            m_BillingAudit.UpdateBillingAudit(rowView["MRN"].ToString(), Convert.ToInt32(rowView["NO"].ToString()),
                                cprFix);
                           
                            dgvPatientstoReview.Rows[e.RowIndex].Cells["DaysAtPatient"].Value = newDays.ToString();
                            dgvPatientstoReview.Rows[e.RowIndex].Cells["Diff"].Value = "0".ToString();
                        }
                    }
                }

            }
            if (this.dgvPatientstoReview.Columns[e.ColumnIndex].Name == this.CPRFixed.Name)
            {
                string checkbox = this.dgvPatientstoReview.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue.ToString();

                if (checkbox.Equals("True".ToString()))
                    cprFix = 1;
                else
                    cprFix = 0;
                DataRowView rowView = (DataRowView)this.m_srcBillingAudit.Current;
                m_BillingAudit.UpdateBillingAudit(rowView["MRN"].ToString(), Convert.ToInt32(rowView["NO"].ToString()), cprFix);
            }
           
        }

Checkbox-problem.docx
0
 

Author Closing Comment

by:LenTompkins
ID: 36980211
Since I never got it to work the way you suggested, I performed the task a different way.  Thank you for your partial assistance.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question