Solved

problem setting a check box from cell leave

Posted on 2011-09-30
7
250 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 74

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 74

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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 74

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now