Home Forums WinForms controls Xceed Grid for WinForms Updating a Cells upon a previous cells change

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16595 |

    I am kind of new to xceed and we are currently working with a contractor who is developing a station program for us. I have been looking at the forums to find an answer to his question but have been having no luck. The issue that is occuring is that there is a ComboBoxEditor which grabs the data from a data set that is populated with ID’s and Name’s. He uses the CellEditorManager and CellViewerManager to display the information. This same logic is used in two columns. The first one is supposed to filter out the data of the second one.

    SelectQuestionType populates the first column

    Private Sub SelectQuestionType()

    ‘Created By (Date): Sunoj Skariah(11/06/08)

    ‘Pupose: Add Question Type into Grid combo box. Data set is called from Class.

    ‘Specifications: The main data set is comes from DB class.

     

    Try

    Dim clsSM As New dbStationAssociation

    ds = clsSM.GetQuestionType()

    Dim cmbQnType As New ComboBoxEditor(ds.Tables(0), String.Empty, “QuestionType”)

    Dim cmbViewerQnType As New ComboBoxViewer(ds.Tables(0), String.Empty, “QuestionType”, “%QuestionType%”)

    ‘Add handler for comboboxviewer1

    AddHandler cmbQnType.GettingControlValue, AddressOf ComboHandler

    cmbQnType.TemplateControl.DisplayFormat =

    “%QuestionType%”

    cmbQnType.TemplateControl.Columns(

    “qg_id”).Visible = False

    GridControl1.Columns(

    “QuestionType”).CellEditorManager = cmbQnType

    GridControl1.Columns(

    “QuestionType”).CellViewerManager = cmbViewerQnType

    Catch ex As Exception

    MessageBox.Show(ex.Message)

    End Try

    End Sub

     

    And Select QuestionName gets the values to be delivered into the second column based on the first column.

    Private Sub SelectQuestionName()

    ‘Created By (Date): Sunoj Skariah(11/06/08)

    ‘Pupose: Add Question Names into Grid combo box. Data set is called from Class.

    ‘Specifications: The main data set is comes from DB class.

    Dim clsSM As New dbStationAssociation

    Try

    ds1 = clsSM.GetQuestionName(GridControl1.CurrentCell.Value.GetHashCode)

    Dim cmbQnName As New Editors.ComboBoxEditor(ds1.Tables(0), String.Empty, “QuestionName”)

    Dim comboBoxViewer1 As New ComboBoxViewer(ds1.Tables(0), String.Empty, “QuestionName”, “%QuestionName%”)

    cmbQnName.TemplateControl.DisplayFormat =

    “%QuestionName%”

    cmbQnName.TemplateControl.Columns(

    “QID”).Visible = False

    GridControl1.Columns(

    “QuestionName”).CellEditorManager = cmbQnName

    GridControl1.Columns(

    “QuestionName”).CellViewerManager = comboBoxViewer1

    Catch ex As Exception

    MessageBox.Show(ex.Message)

    End Try

     

    End Sub

     

    The problem we are having is that the Handler fires only after the cell is clicked out of. But the value on the GridControl1 has not been updated. It only gets updated after all the filtering is done. So the second column is allways one full step behind and is never the current data. Any help would be appreciated. If anyone has a better way to handle this that is great to. Currently I can not seem to get access to the value of the CellEditorManager at all. Thank You in Advance.

    Imported from legacy forums. Posted by Grant (had 1557 views)

    User (Old forums)
    Member
    Post count: 23064

    What you need is to subscribe to events on the ComboBox editor as such, so that when the SelectedValue changes in the first ComboBox, you can prepare the binding for the second one, and then bind it properly when it actually get activated.

    In order to subscribe to ComboBox events, you need to first subscribe to the ActivatingControl event of the CellEditorManager.  This is necessary because the editor is actually initialized only when the cell receives focus, and enters the edit mode.

    e.g.:

    //at Form_Load

      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        AddHandler GridControl1.Columns( 0 ).CellEditorManager.ActivatingControl, AddressOf CheckBoxEditor_ActivatingControl
        AddHandler GridControl1.Columns( 0 ).CellEditorManager.DeactivatingControl, AddressOf CheckBoxEditor_DeactivatingControl

      End Sub

    //Event handlers

      Private Sub CellEditorManager_ActivatingControl( ByVal sender As Object, ByVal e As Xceed.Grid.Editors.CellEditorEventArgs )

        Dim editor as Xceed.Editors.WinComboBox = CType( e.Control, Xceed.Editors.WinComboBox )
        AddHandler editor.SelectedIndexChanged, AddressOf editor_SelectedIndexChanged

      End Sub

      Private Sub CellEditorManager_DeactivatingControl( ByVal sender As Object, ByVal e As Xceed.Grid.Editors.CellEditorEventArgs )
       
        Dim editor as Xceed.Editors.WinComboBox = CType( e.Control, Xceed.Editors.WinComboBox )
        ‘this needs to be done, if not, subscriptions will pill up every time the editor is activated
        RemoveHandler editor.SelectedIndexChanged, AddressOf editor_SelectedIndexChanged
     
      End Sub

      Private sub editor_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As EventArgs )

        Dim index As String = “index ” + CType( sender, WinComboBox ).SelectedIndex.ToString()
        System.Diagnostics.Debug.WriteLine( index )
        
      End Sub

    Imported from legacy forums. Posted by André (had 380 views)

    User (Old forums)
    Member
    Post count: 23064

    Thank you that gives me a good start to get this working. It seems like things are working good.

    Imported from legacy forums. Posted by Grant (had 742 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.