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. Image for the cookie policy date

Accessing the Selected Item Value in Databound Grid Combo

I am stuggling with something that seems like it should be easy. I am trying to detect a change in a databound grid combobox cell, and then use the combobox selected value to set other controls on the form. The CurrentCellChanged event is firing based on the users selection, but the CellValue and Text properties of the current cell are not updated. I can press the save button on the form and query the underlying dataview and the data has been updated. Is there a different event I should be using? Here is a code sample: Private Sub dbgReviewApprove_CurrentCellValidated(ByVal sender As Object, ByVal e As System.EventArgs) Handles dbgReviewApprove.CurrentCellValidated Dim introw As Integer intRow = dbgReviewApprove.CurrentCell.RowIndex Select Case dbgReviewApprove.Item(introw, 7).CellValue Case 1, 3 Case 2 ' Change the Approval Date dbgReviewApprove.Item(introw, 6).Text = DateTime.Now.ToShortDateString End Select End Sub Thanks - Anthony

5 Replies

AD Administrator Syncfusion Team February 6, 2003 05:25 PM

Try CurrentCellAcceptedChanges. This is fired after the pending changes in the current cell have been transferred to the underlying cell. In CurrentCellAcceptedChanges you can get the cell value from the underlying cell. CurrentCellValidating is called before the changes are saved in the underlying cell that's why the .Cell Value returns the old value at that time. Stefan


AN Anthony February 6, 2003 05:46 PM

Stefan - Thanks for the response. CurrentCellAcceptedChanges was a step in the right direction. It does contain the updated values, but it does not appear to fire until the cell loses focus. When is the cell data actually updated? When the cell loses focus? Thanks - Anthony


AD Administrator Syncfusion Team February 7, 2003 01:03 AM

CurrentCellChanged and CurrentCellValidating are raised when changes were made in the current cell while in editing mode. At this time the cell value is only a temporary state of the edited cell. Before the cell value can be stored in the underlying cell it needs to be validated. This validation occurs when the user is satisfied with his text entry and ok's it. That's when CommitChanges is called which triggers CurrentCellValidating and after saving CurrentCellAcceptedChanges. You can force saving the data into the cell by explicitly calling CurrentCell.CommitChanges(). CommitChanges() will validate the cell contents and store the value in the cell style. The cell renderer will neither be deactivated nor loose focus. Another property you should look at is CurrentCell.Renderer.ControlValue. At the time CurrentCellChanged is raised the state of the current cells ControlValue is up to the specific cell editor. Most cells save the CurrentCell.ControlValue based on the current text before CurrentCellChanged is raised. But, it cannot be guaranteed that each cell renderer will do that. Most accurate is ControlText. It will return the text that is displayed in the cell but ControlValue must be explicitly generate by the renderer (and is only of use when you want to extend the cell type). We try to make all our cell editor do that and generate a CurrentCell.ControlValue before CurrentCellChanged when approbriate. If you are using the latest patch (I think 1.5.1.3 or higher) you should be able to access CurrentCell.ControlValue with a combobox and it should return the future cell value based on the text that is actually selected in the cell. Also, look for the CurrentCellClosedDropDown event. Stefan


AN Anthony February 8, 2003 11:23 AM

Stefan - Once again thank you for the response, but I am still confused. In your response you directed me to check the CurrentCell.ControlValue and CurrentCell.ControlText properties in the listed event procedures. When I do that, I get the message 'ControlText' is not a member of 'GridCurrentCell'. The type of the dbg.currentcell property is Syncfusion.Windows.Forms.Grid.GridCurrentCell. Should I be casting this to a different type to get at the properties you mentioned? In the end this is the approach that I took. In the CurrentCellCloseDropDown event, I called dbg.CommitChanges method which triggered the CurrentCellAcceptedChanges event. In the CurrentCellAcceptedChanges event I am able to get the correct value by using : dbg.Item(dbg.CurrentCell.RowIndex, dbg.CurrentCell.ColIndex).CellValue If there is a more efficient approach, or if this may present unforseen side effects. please let me know. Thanks again - Anthony Mansfield > CurrentCellChanged and CurrentCellValidating are raised when changes were made in the current cell while in editing mode. At this time the cell value is only a temporary state of the edited cell. Before the cell value can be stored in the underlying cell it needs to be validated. This validation occurs when the user is satisfied with his text entry and ok's it. That's when CommitChanges is called which triggers CurrentCellValidating and after saving CurrentCellAcceptedChanges. > > You can force saving the data into the cell by explicitly calling CurrentCell.CommitChanges(). CommitChanges() will validate the cell contents and store the value in the cell style. The cell renderer will neither be deactivated nor loose focus. > > Another property you should look at is CurrentCell.Renderer.ControlValue. At the time CurrentCellChanged is raised the state of the current cells ControlValue is up to the specific cell editor. Most cells save the CurrentCell.ControlValue based on the current text before CurrentCellChanged is raised. But, it cannot be guaranteed that each cell renderer will do that. Most accurate is ControlText. It will return the text that is displayed in the cell but ControlValue must be explicitly generate by the renderer (and is only of use when you want to extend the cell type). We try to make all our cell editor do that and generate a CurrentCell.ControlValue before CurrentCellChanged when approbriate. > > If you are using the latest patch (I think 1.5.1.3 or higher) you should be able to access CurrentCell.ControlValue with a combobox and it should return the future cell value based on the text that is actually selected in the cell. Also, look for the CurrentCellClosedDropDown event. > > Stefan >


AD Administrator Syncfusion Team February 8, 2003 11:32 AM

I think you should be fine with what you do now. I meant CurrentCell.Renderer.ControlText and CurrentCell.Renderer.ControlValue. Sorry about that mixup. Stefan

Loader.
Live Chat Icon For mobile
Up arrow icon