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

Dropdown selected item issue

We''re using a dropdown combobox, the GridListControl version, editable, bound to a datasource (an araylist). Works fine except for 1 thing. The first time the combobox is dropped down, the first item in the list appears selected, even though it is not acually selected, and doesn''t match the text in the cell (the text is empty at this point). Once you select an item, then it displays that item as selected the next time it''s dropped down, as it should. I can''t see why it displays the first item as selected, the first time the combobox displays. Is there a way to specifically clear the selection of the combo box? Or is there some setting that governs the initial display of the dropdown? The control works well and consistently except for the first time it''s displayed.

8 Replies

AD Administrator Syncfusion Team February 17, 2005 08:42 PM UTC

Try handling the CurrentcellShowingDropDown event as below. private void gridControl1_CurrentCellShowingDropDown(object sender, GridCurrentCellShowingDropDownEventArgs e) { GridCurrentCell cc = this.gridControl1.CurrentCell; GridDropDownGridListControlCellRenderer cr = cc.Renderer as GridDropDownGridListControlCellRenderer; if(cr != null) { GridListControl glc = cr.ListControlPart as GridListControl; glc.SelectedIndex = 1; } }


JE jeugenides February 17, 2005 08:53 PM UTC

Kewl, that works. Thanks much.


JL Jeff Lancaster April 22, 2005 12:21 AM UTC

I am having the same issue, and tried this solution modified for VB and to work in my grid as follows: Dim cr As GridComboBoxCellRenderer = m_grid.CurrentCell.Renderer If Not cr Is Nothing Then cr.ListBoxPart.SelectedIndex = 1 End If Unfortunately, this doesn''t solve the problem. It does set the selected index to 1 (the second item in the list) every time the box drops down, however it''s not really active, you have click or use the arrow keys to actually activate a value. I also tried setting the selectedIndex to -1, in the hopes that the list would show nothing selected at all (my preference). Unfortunately, this seems to have no effect, the first time the box drops down the first item in the list still "appears" to be selected (The next time you drop down the list nothing is selected). By the way, all this only occurs when you don''t have a value in the text portion of the combo box yet - if you do have a value the selectedIndex property does nothing and the corresponding value always shows selected. How can I make it so that if there is no value in the text box when the combo drops down, that it will never appear to have an item selected?


AD Administrator Syncfusion Team April 22, 2005 12:34 AM UTC

If I add this handler Private Sub gridControl1_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As GridCurrentCellShowingDropDownEventArgs) Handles gridControl1.CurrentCellShowingDropDown Dim cc As GridCurrentCell = Me.grid.CurrentCell If cc.Renderer.ControlText = "" Then Dim cr As GridComboBoxCellRenderer = cc.Renderer If Not cr Is Nothing Then '' cr.ListBoxPart.SelectedIndex = -1 End If End If End Sub to the \Syncfusion\Essential Suite\3.0.1.0\Windows\Grid.Windows\Samples\CellTypes\ComboboxCells sample, when the cells are initially dropped (with empty text boxes), there are not items selected in the list. Does this not work for you? If not, can you tell us how to see the problem in that sample, or upload a sample showing the problem?


JL Jeff Lancaster April 22, 2005 06:49 PM UTC

You''re right - if you add that code in the sample there are no selected items in the list. In fact, in the sample, there are no selected items in the list even if you don''t add that code. However, I may have found a problem in the sample that is related and will provide a clue as to what is going on. Add your code to the sample, but change the SelectedIndex to a positive 1. The first time the list drops there are no items selected. However the rest of the time it selects the second item in the list. This looks like it may be a similar issue to the one I''m having in my program. By the way, I''m using version 3.0.1.1 in case it makes any difference. Thanks, Jeff


AD Administrator Syncfusion Team April 23, 2005 12:09 AM UTC

The code I suggested for above was for the comboboxes and not GridListControl cells. In that same sample, if you try the GridListControls, I think you will see the behavior you described. IE., on teh first drop of an empty cell, the first row in the GridListControl is highlighted. This behavior is from the GridListControl itself. I was able to avoid this selected look by hiding the selection itself. Here is the code I used in that sample.
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim cr As GridDropDownGridListControlCellRenderer = Me.gridControl1.CellRenderers("GridListControl")
        If Not cr Is Nothing Then
            AddHandler cr.ListControlPart.Grid.SelectionChanged, AddressOf SelectionChanged
        End If
        Me.gridControl1(40, 3).Text = "ANTON"
    End Sub ''Form1_Load
    Private Sub SelectionChanged(ByVal sender As Object, ByVal e As GridSelectionChangedEventArgs)
        Dim cr As GridDropDownGridListControlCellRenderer = Me.gridControl1.CellRenderers("GridListControl")
        cr.ListControlPart.Grid.AlphaBlendSelectionColor = Color.FromArgb(80, cr.ListControlPart.Grid.AlphaBlendSelectionColor)
    End Sub
    Private Sub gridControl1_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As GridCurrentCellShowingDropDownEventArgs) Handles gridControl1.CurrentCellShowingDropDown
        Dim cc As GridCurrentCell = Me.grid.CurrentCell
        If cc.Renderer.ControlText = "" Then
            Dim cr As GridDropDownGridListControlCellRenderer = cc.Renderer
            If Not cr Is Nothing Then
                 cr.ListControlPart.Grid.AlphaBlendSelectionColor = Color.FromArgb(0, cr.ListControlPart.Grid.AlphaBlendSelectionColor)
            End If
        End If
    End Sub


JL Jeff Lancaster April 25, 2005 06:07 PM UTC

Thanks Again, Clay. I see what you are saying, and this latest piece of code does modify the behavior of the gridlist controls in your sample. However the issues I am seeing, both in my grid and your sample actually pertain to the combobox''s. I tried the following code both in my application and in your sample: Private Sub gridControl1_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCurrentCellShowingDropDownEventArgs) Handles gridControl1.CurrentCellShowingDropDown Dim cc As GridCurrentCell = Me.grid.CurrentCell If cc.Renderer.ControlText = "" Then Dim cr As GridComboBoxCellRenderer = cc.Renderer If Not cr Is Nothing Then cr.ListBoxPart.SelectedIndex = -1 End If End If End Sub When, I do this, I see no difference in the way your sample works, or mine either. In yours, the combos continue to drop with the selections clear everytime. With mine, the combo''s still drop with the first item selected the first time, then no items selected on consecutive tries. Next, I tried changing the selectedIndex value in both apps to a positive 1. In your sample, the result of this is that the combo drops with nothing selected the first time. If you then move off the field then go back and drop it again, the 2nd item (index 1) is properly selected. In my app, this code actually causes the 2nd item to be selected every time. However, what I want in mine is nothing selected unless there is already a value in the text field. Looks like there are two puzzles here: First of all, why would mine be behaving differently than your sample, and secondly and perhaps more importantly, why does setting the selected index value in your sample, not effect the combo until the second time it drops? Perhaps finding the answer to this second question would provide a clue as to how to fix my application. Jeff


JL Jeff Lancaster April 28, 2005 09:44 PM UTC

Just checking in - wondered if anyone might be looking into this issue (hopefully it hasn''t been forgotten)? Thanks, Jeff

Loader.
Live Chat Icon For mobile
Up arrow icon