Solved

problem setting a check box from cell leave

Posted on 2011-09-30
7
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

622 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