GroupSummaryEvaluate

1 Answer 32 Views
GridView
Hell
Top achievements
Rank 1
Iron
Iron
Hell asked on 19 Jan 2025, 08:22 AM | edited on 19 Jan 2025, 11:43 AM

I use the following code to group and format the group name.

Private Sub grdURLs2_GroupSummaryEvaluate(sender As Object, e As GroupSummaryEvaluationEventArgs) Handles grdURLs2.GroupSummaryEvaluate
    Try
        Dim groupRow As GridViewGroupRowInfo = TryCast(e.Context, GridViewGroupRowInfo)
        If e.SummaryItem.Name = "col1" Then
            If groupRow IsNot Nothing Then
                If e.Value IsNot Nothing Then
                    e.FormatString = e.Value
                Else
                    e.FormatString = ""
                End If
            End If
        End If
    Catch ex As Exception
        txtError.Text = ex.Message & " - " & Format(Now, "HH:mm:ss")
    End Try
End Sub

Everything works fine until I leave the group field empty. This code works fine with an empty field, but after restarting the program, it adds records with empty fields not to the same group, but creates a new one. After restarting the program, all fields are in the same group. What am I doing wrong and how can I do it right? Thank you!

P.S.: I figured out why this happens.

Then another question arises. How to check cells for empty values ​​when adding a record and not add records with empty cells (continue editing)? Or replace empty values ​​in cells with significant ones and add?

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 20 Jan 2025, 03:15 PM

Hello,

According to this question: "How to check cells for empty values ​​when adding a record and not add records with empty cells (continue editing)?" can you please specify how exactly you add new rows. Are you using the new row functionality in grid that allows you to add new row by filling the cells as in the picture: 

If you are adding new rows, by clicking on the "Click here to add a new row", I would like to note that there is UserAddingRow event which you can handle and validate cells from empty values. You can cancel the event if the cell value is empty, and thus prevent the grid from adding the new row. Thus, you can validate that the row will always have values in the cells. Please refer to the following article and example: New Row - WinForms GridView Control - Telerik UI for WinForms

As to the second question: " Or replace empty values ​​in cells with significant ones and add?", you can apply default values if you want to by handling the DefaultValuesNeeded event.  If not changed by the end-user, are saved in the row when the new row is committed by the end-user. More information is available here: New Row - WinForms GridView Control - Telerik UI for WinForms

I hope this information is useful. If you have any other questions do not hesitate to ask.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Hell
Top achievements
Rank 1
Iron
Iron
commented on 20 Jan 2025, 05:07 PM | edited

Thank you very much for the link. UserAddingRow() worked perfectly.

Private Sub grdURLs2_UserAddingRow(sender As Object, e As GridViewRowCancelEventArgs) Handles grdURLs2.UserAddingRow
    Try
        If e.Rows(0).Cells(0).Value Is Nothing OrElse
            String.IsNullOrEmpty(Trim(e.Rows(0).Cells(0).Value)) Or
            e.Rows(0).Cells(1).Value Is Nothing OrElse
            String.IsNullOrEmpty(Trim(e.Rows(0).Cells(1).Value)) Then
            e.Cancel = True
        Else
            For Each row In grdURLs2.Rows
                If e.Rows(0).Cells(1).Value = row.Cells(1).Value Then
                    e.Cancel = True
                    Exit For
                End If
            Next
        End If
    Catch ex As Exception
        txtError.Text = ex.Message & " - " & Format(Now, "HH:mm:ss")
    End Try
End Sub

I just didn't understand about CancelAddNewRow(). For example, this doesn't work as I would like (One ESC). Two ESCs are still required (finish editing and cancel adding). CommandCellClick() works only by transferring focus from the Cells (finish editing) to the CommandButton::

   Private Sub frmCheckVersions_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
       If e.KeyCode = 27 Then
           grdURLs2.MasterView.TableAddNewRow.CancelAddNewRow()
       End If
   End Sub
Can you explain? Thank you!
Nadya | Tech Support Engineer
Telerik team
commented on 21 Jan 2025, 02:38 PM

Hello,

I am glad to hear that the UserAddingRow worked perfectly. 

The CancelAddNewRow method is a special method to cancel the edit operation from the new row. By default, the first Escape cancels cell edit and the second one cancels the whole process of adding a new row. It is not needed to handle KeyDown event and cancel the edit. This happens by default. Do you need to change something in this current behavior?

When you call CancelAddNewRow(), let's say on a button.Click or CommandCellClick event, you directly stop the editing process and prevent the new row from submitting any values. It cancels the whole process. This event is introduced to come in handy in different client scenarios. We provide you with different options, it is up to the developer to consider which canceling to choose according to its specific needs. If the UserAddingRow is working for you, it might not be necessary to use CancelAddNewRow. 

Note, RadGridView manages user mouse and keyboard input over its rows by GridRowBehavior. Depending on the row type, RadGridView introduces different behaviors. If you need to change the behavior when pressing the Esc key, you should refer to the following article: Row behaviors - WinForms GridView Control - Telerik UI for WinForms

I hope this information helps. Please let me know if you need further assistance. 

Hell
Top achievements
Rank 1
Iron
Iron
commented on 21 Jan 2025, 03:05 PM | edited

Thank you!
Tags
GridView
Asked by
Hell
Top achievements
Rank 1
Iron
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or