We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Dynamic synchronization between winform controls and GridGroupingControl

Thread ID:

Created:

Updated:

Platform:

Replies:

124647 Jun 20,2016 02:14 PM Jun 28,2016 12:49 AM Windows Forms 12
loading
Tags: GridGroupingControl
Nicolas
Asked On June 20, 2016 02:14 PM

Hi, I have forms where I have the standard Winform controls (ComboBox, TextBox, Checkbox) which shows the values of a row in GGC which is also present in the form.

If I make a change in any of the controls (or in GCC current row), the update value in the counterpart (controls or GGC) is only shown once a new row has been selected and after we return to the starting row, hence recorded. So basically, the values are not changing dynamically

I actually have a part of the program that can actualize dynamically from the GGC to the WinForm Combobox - Whenever I commit a change in a GridCellType.ComboBox, I use : 

Private Sub GridGroupingControl1_TableControlCurrentCellCloseDropDown(sender As Object, e As GridTableControlPopupClosedEventArgs) Handles GridGroupingControl1.TableControlCurrentCellCloseDropDown

   If e.TableControl.CurrentCell.Renderer.Model.Description = "GridComboBoxCellModelDesc" Then

     Dim renderer As GridComboBoxCellRenderer = GridGroupingControl1.TableControl.CurrentCell.Renderer

     If (renderer.ColIndex = 1) Then

     ComboBoxNameInControls.SelectedIndex = renderer.ListBoxPart.SelectedIndex

   End If

End sub

This


This triggers the SelectedIndex event for the Winform ComboBox (Private Sub ComboBoxNameInControl_SelectedIndexChanged (sender as object, e As EventArgs) Handles ComboBoxNameInControl.SelectedIndexChanged) and update it dynamically.


I have 3 questions related to this: 

1) what procedures shall I follow to do the same with textboxes (on each side)

2) what event shall I pick on each side (WinForm and GGC) to get a perfectly synchronized form - and is it possible to avoid an event for each and every control (a more general approach)

3) I have an audit trail on the GGC side, with an event "GridGroupingControl1_RecordValueChanging" : is it possible to fire this event whenever a change is made on the WinForm controls side?


Thanks in advance!!! - Nicolas





Piruthiviraj Malaimelraj [Syncfusion]
Replied On June 21, 2016 10:23 AM

Hi Nicolas, 

Thank you for using Syncfusion products. 

In order to synchronize the grid with winforms controls while changing the records of the table , you can bind the datasource of the grid to the winforms controls using DataBindings property of that controls. We have dashboard sample for binding records at runtime. Please refer to the sample from below location. 

Sample location:  
 
<InstalledLocation\Syncfusion\EssentialStudio\<version number>\Windows\Grid.Grouping.Windows\Samples\Getting Started\Record Binding Demo\CS> 

Regards, 
Piruthiviraj 


Nicolas
Replied On June 22, 2016 02:27 PM

Hi! The example you provided is ok, and my grid has the same performance but the "problem" still remains : the Grid / Textbox are only updated once the record selection has changed. Is it possible to update Grid/Control before that? Thanks - Nicolas

Piruthiviraj Malaimelraj [Syncfusion]
Replied On June 23, 2016 08:20 AM

Hi Nicolas, 

Thank you for your update. 

In order to update the grid , when changing the value of the winforms controls, you need to refresh the grid and set the current value for the grid. To also update the winforms controls from the grid, SourceListListChanged event can be used. Please make use of below code and refer to the attached sample. 

Code snippet 
 
this.textBox1.KeyDown += textBox1_KeyDown; 
//To update the grid without change selection 
void textBox1_KeyDown(object sender, KeyEventArgs e) 
{ 
    if (e.KeyCode == Keys.Enter) 
    { 
        this.gridGroupingControl1.Table.CurrentRecord.SetValue("Col1", this.textBox1.Text); 
        this.gridGroupingControl1.Refresh(); 
    } 
} 
 
this.gridGroupingControl1.SourceListListChanged += gridGroupingControl1_SourceListListChanged; 
//To update the WinformControls while changing the current cell value 
void gridGroupingControl1_SourceListListChanged(object sender, Syncfusion.Grouping.TableListChangedEventArgs e) 
{ 
    if (e.ListChangedType == ListChangedType.ItemChanged) 
    { 
        e.Table.TableDirty = true; 
    } 
} 

Sample link 

Regards, 
Piruthiviraj 


Nicolas
Replied On June 23, 2016 02:00 PM

Hi! the sample provided is missing the 2015 version of VS, but anyways I tried the code provided, and it works like a charm for the Controls to Grid side! I used the TextBox.Validating event instead of KeyDown event for the TextBox. 
    Private Sub oTraining_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles oTraining.Validating
        GridGroupingControl1.Table.CurrentRecord.SetValue("otraining", oTraining.Text)
        GridGroupingControl1.Refresh()
    End Sub

I wonder if there is a way to trigger the event GridGroupingControl1_RecordValueChanging in the otraining.validating event? 

The opposite is however not working as expected (Grid to Control) even if I imported the System.ComponentModel, any idea of what could be wrong?

Thanks for the great support !!! Nicolas

Piruthiviraj Malaimelraj [Syncfusion]
Replied On June 24, 2016 10:50 AM

Hi Nicolas, 
 
Thank you for your update. 
 
We had analyzed the your query. In our previous update, we have provided the solution to update the grid from WinForms controls by SourceListListChanged event and also to update winforms controls to grid by textBox1.KeyDown event. If you are using textBox1.validating event, the grid will be updated when the record selection is changed which what you have reported in your previous update. RecordValueChanging event will be triggered when you are changing the cell value of the grid so when the textbox value has changed , this event will be automatically triggered because these controls are using binding context. Could you please provide us with details about why you are using textBox1.validating event to update the grid? 
 
Regards, 
Piruthiviraj 


Nicolas
Replied On June 24, 2016 04:29 PM

Hi Piruthiviraj!

I installed an older version of VS to understand your programming, and I saw the difference : the ENTER key press is what's updating from GRID to CTL (triggering the SourceListListChanged) - so basically, it now works both ways for the updating, I added an event where I generate an ENTER in the grid for the users that do not press enter ENTER for each field - that yields the same result

    Private Sub GridGroupingControl1_TableControlCurrentCellValidating(sender As Object, e As GridTableControlCancelEventArgs) Handles GridGroupingControl1.TableControlCurrentCellValidating
        SendKeys.Send("{ENTER}")
    End Sub

As for your question, I use the validating event in the Textbox for the same users that do not press ENTER, but rather change Textbox when they are finished completing one, it is not as instantaneous as the Key press event (your event is better in that point of view, as long as the user is using the key press...), but basically the job is done

    Private Sub oTraining_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles oTraining.Validating
        Call modMain.DynamicCTLToGGC(GridGroupingControl1, "otraining", oTraining.Text) 'This is the program lines you made I placed in a sub
        'Here raise the event : GridGroupingControl1_RecordValueChanging
    End Sub

Now, the RecordValueChanging is an important event for me as it yields the Audit Trail sub as follows :

    Private Sub GridGroupingControl1_RecordValueChanging(sender As Object, e As RecordValueChangingEventArgs) Handles GridGroupingControl1.RecordValueChanging
        Call modMain.AuditTrailGGC(GridGroupingControl1, sender, e, "Edit", Me.PID.Text)
    End Sub

As I explained earlier, the RecordValueChanging is triggered easily whenever the user is changing values in the grid. However, I am still missing the piece that will trigger this event whenever a user is changing data from the windows' controls

All the best! - Nicolas

Nicolas
Replied On June 24, 2016 04:36 PM

P.S. I tried using the KeyPress event for the Textbox to check if it was triggering or not the RecordValueChanging event, and apparently it is not
- Nicolas

Piruthiviraj Malaimelraj [Syncfusion]
Replied On June 27, 2016 08:33 AM

Hi Nicolas, 

Thank you for your update. 

The RecordValueChanging event can be manually triggered by using the RaiseRecordValueChanging method of grid Table. Please make use of below code. 

Code snippet 
Private Sub textBox1_Validating(ByVal sender As Object, ByVal e As CancelEventArgs) 
                If Me.gridGroupingControl1.Table.CurrentRecord IsNot Nothing Then 
                                'Raise the event. 
                                Dim eventArgs As New RecordValueChangingEventArgs(Me.gridGroupingControl1.Table.CurrentRecord, "Col1", Me.gridGroupingControl1.TableDescriptor.Columns("Col1").FieldDescriptor, Me.textBox1.Text) 
                                Me.gridGroupingControl1.Table.RaiseRecordValueChanging(eventArgs) 
 
                End If 
End Sub 
 
Regards, 
Piruthiviraj 


Nicolas
Replied On June 27, 2016 09:41 AM

That's really great!!! Thanks a bunch, works like a charm! - Nicolas

Nicolas
Replied On June 27, 2016 09:50 AM

I noticed that it's not picking up the old value, let me see if I can resolve - Thanks! - Nicolas

Nicolas
Replied On June 27, 2016 01:39 PM

Resolved! Just need to re-order the timing of the event (before setting the value to the GGC)

Sub DynamicCTLToGGC(GGC As GridGroupingControl, Fld As String, ByVal Val As String)
    Dim eventArgs As New RecordValueChangingEventArgs(GGC.Table.CurrentRecord, Fld, GGC.TableDescriptor.Columns(Fld).FieldDescriptor, Val)
    GGC.Table.RaiseRecordValueChanging(eventArgs)
    GGC.Table.CurrentRecord.SetValue(Fld, Val)
end sub

Thanks to the team ! - Nicolas

Piruthiviraj Malaimelraj [Syncfusion]
Replied On June 28, 2016 12:49 AM

Hi Nicolas, 

We are glad to hear from you that the issue is resolved. Please let us know if you have any other queries. 

Regards, 
Piruthiviraj 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;