This is a migrated thread and some comments may be shown as answers.

Cell Group validation

7 Answers 123 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Charles Nelson
Top achievements
Rank 1
Charles Nelson asked on 13 Sep 2010, 05:30 PM
I am creating a small application using the RadGridview for Silverlight which validates whether a group of cells in the same row summ to one.  if they do not sum to on then validation for the row fails.  I am attempting to  set the focus to the first cell of the group which fails validation using the below code:

private void gvRiskMetrics_RowValidating(object sender, Telerik.Windows.Controls.GridViewRowValidatingEventArgs e)
        {
            RMSectorWeightEnt SectorWeightENT = e.Row.DataContext as RMSectorWeightEnt;
            List<double?> GroupSums = checkGroupSums(SectorWeightENT);
            int isum = 0;
            foreach (double sum in GroupSums)
            {
                if (sum != 1)
                {
                   
                   
                    GridViewCellValidationResult validationResult = new GridViewCellValidationResult();
                    validationResult.PropertyName = "Sums";
                    validationResult.ErrorMessage = "Sum must be equal to 1";
                    e.ValidationResults.Add(validationResult);
                    
                    e.IsValid = false;
                
                  
  int Index = gvRiskMetrics.SelectedItems.IndexOf(gvRiskMetrics.SelectedItem);
               var item = gvRiskMetrics.Items[Index];
                  var column = gvRiskMetrics.Columns[m_GroupItemsIndex[isum]];
                   gvRiskMetrics.ScrollIntoView(item, column);
          var cellinfo = new GridViewCellInfo(item, column, gvRiskMetrics);
                gvRiskMetrics.CurrentCellInfo = currentCell;
                   gvRiskMetrics.BeginEdit();

                    
                }
                isum++;
            }
            
        }

Apparently this won't work since every time the current cell info is updated the the RowValidating event is called and the application essentially goes into an infinite loop.  Do you have any suggestions?  One other thing here is this behaviour does not occur on the first item in the Gridview collection(Row 1).

7 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 16 Sep 2010, 03:34 PM
Hi Charles Nelson,

You can achieve this by little modification of your code:

private void gvRiskMetrics_RowValidating(object sender, Telerik.Windows.Controls.GridViewRowValidatingEventArgs e)
        {
            RMSectorWeightEnt SectorWeightENT = e.Row.DataContext as RMSectorWeightEnt;
            List<double?> GroupSums = checkGroupSums(SectorWeightENT);
            int isum = 0;
            foreach (double sum in GroupSums)
            {
                if (sum != 1)
                {
                    
                    
                    GridViewCellValidationResult validationResult = new GridViewCellValidationResult();
                     
                    validationResult.PropertyName = "property name of the column which should enter into edit mode";
                    // Generally this is column.DataMemberBinding.Path.Path string
                     
                    validationResult.ErrorMessage = "Sum must be equal to 1";
                    e.ValidationResults.Add(validationResult);
                     
                    e.IsValid = false;
                 
                   
  //int Index = gvRiskMetrics.SelectedItems.IndexOf(gvRiskMetrics.SelectedItem);
  //             var item = gvRiskMetrics.Items[Index];
  //                var column = gvRiskMetrics.Columns[m_GroupItemsIndex[isum]];
  //                 gvRiskMetrics.ScrollIntoView(item, column);
  //        var cellinfo = new GridViewCellInfo(item, column, gvRiskMetrics);
  //              gvRiskMetrics.CurrentCellInfo = currentCell;
  //                 gvRiskMetrics.BeginEdit();
 
                     
                }
                isum++;
            }
             
        }

Let me know how it works on your end.

Best wishes,
Nedyalko Nikolov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Charles Nelson
Top achievements
Rank 1
answered on 21 Sep 2010, 04:25 PM
Can't I just use the column.UniqueName property here?  Also this does not shift to the cell which has a problem.  Let me explain further. This simple application exposes a simple editble grid to which a user can add values.  Certain column groups on a row must add to 1 and must not be null.  The application prevents  saving ull values ot the db and upon vaildation I want the faocus to move to the group of cells on the selected row which has a null/or invalid value.  your code does not seem to work in this manner and seems to only focus on the last edited cell.  hope this is clear.

Charles.
0
Nedyalko Nikolov
Telerik team
answered on 24 Sep 2010, 08:01 AM
Hi Charles Nelson,

RadGridView will focus the cell which is related to "PropertyName" value. For example if your BO has 3 properties (prop1, prop2, prop3). If you set validationResult.PropertyName = "prop2" then second cell will enter into edit mode after RowValidating. Generally if UniqueName is equal to the name of the property you could use UniqueName too.

Greetings,
Nedyalko Nikolov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Stephen
Top achievements
Rank 2
answered on 01 Mar 2011, 11:18 AM
Trying to find a way to clear the error symbol on the row, after correcting the problem (and clearing the validation error). 
This GridViewCellValidationResult can be used to add an error in the rowValidating but i'm trying to clear the error
state in the CellValidating so that fixing the error clears it until they try to submit the row again. 

any ideas?
0
Emanuel Varga
Top achievements
Rank 1
answered on 01 Mar 2011, 01:24 PM
Hello Stephen,

Can you please open a new thread and submit some code with what you are trying to achieve, it will be a lot easier to get help like that.

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Emanuel Varga
Top achievements
Rank 1
answered on 01 Mar 2011, 01:25 PM
Hello again,

I forgot to mention that if you just want to remove the symbol you can just use:
radGridView1.CurrentRow.ErrorText = string.Empty;
//or any rowInfo
radGridView1.Rows[0].ErrorText = string.Empty

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Stephen
Top achievements
Rank 2
answered on 02 Mar 2011, 02:04 AM
not sure what I'm missing here... my RadGridView does not have a CurrentRow property. There is a CurrentCell but no ErrorText on that property. 

I'll put together some example code and post a new thread. 
Update: I think you are refering to Winforms RadGridView or perhaps WPF. I'm using Silverlight RadGridView...

thanks,
Stephen
Tags
GridView
Asked by
Charles Nelson
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Charles Nelson
Top achievements
Rank 1
Stephen
Top achievements
Rank 2
Emanuel Varga
Top achievements
Rank 1
Share this question
or