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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to keep selectedItem when lost focus

Thread ID:

Created:

Updated:

Platform:

Replies:

129886 Apr 7,2017 08:49 AM UTC Apr 17,2017 11:14 AM UTC WinForms 3
loading
Tags: GridListControl
Truong
Asked On April 7, 2017 08:49 AM UTC

I Have a ComboDropDown which have PopupControl is a GridListControl

I have an event ComboDropDown _TextChanged when user search item , GridListControl.datasource will change

  private void ComboDropDown _TextChanged(object sender, EventArgs e)
        {
             lstHH = lst.Where().ToList();
            GridListControl.DataSource = lstHH;
            ComboDropDown .DroppedDown = true;
            if (GridListControl.Items.Count != 0)
            {
                GridListControl.SelectedItem = GridListControl.Items[0];
            }
        }
I have a problem when set SelectedItem , it can not be select !

How can i can set SelectedItem. Thank for helping !!!

Piruthiviraj Malaimelraj [Syncfusion]
Replied On April 10, 2017 04:55 PM UTC

Hi Truong, 
 
Thanks for your interest in Syncfusion products. 
 
By default, the selection can be set when the control gets focus. So if you want to set the selected item in GridListControl, set the focus to the GridListControl.  
 
Code example: 
void comboDropDown1_TextChanged(object sender, EventArgs e) 
{ 
    this.gridListControl1.DataSource = countries; 
    this.comboDropDown1.DroppedDown = true; 
    if (this.gridListControl1.Items.Count != 0) 
    { 
        this.gridListControl1.Focus(); 
        this.gridListControl1.SelectedItem = this.gridListControl1.Items[0]; 
    } 
} 
 
Note: 
GridListControl can be coupled to a ComboBoxBase control directly and it allows to select the corresponding item based on combobox text value. Please refer to the below UG and DashBoard sample from the below location, 
 
Code example: 
this.comboBoxBase1.ListControl = this.gridListControl1; 
 
UG Document: 
 
DashBoard Sample location: 
<InstalledLocation\Syncfusion\EssentialStudio\VersionNumber\Windows\Grid.Windows\Samples\Grid List Control\Drop-Down Grid Demo> 
 
Regards, 
Piruthiviraj 


Truong
Replied On April 14, 2017 07:30 AM UTC

I can not focus to GridListControl , i want to select the first row of GridListControl when Text value of ComboDropDown changed and do not focus to GridListControl,but it not working, the GridListControl item can not be selected.How a item of GridListControl be selected when the control not focus.I will try with ComboboxBase

Piruthiviraj Malaimelraj [Syncfusion]
Replied On April 17, 2017 11:14 AM UTC

Hi Truong,   
 
Thanks for the update.   
 
By default, In GridListControl , the selected index will be changed based on text typed in ComboBoxDropDown which satisfies the DisplayMember value of GridListControl (Case-Senstive). This is the default behaviour. As per your scenario, you are trying to set the selection when combobox text is changed. So if typed text is same as first item(DisplayMember) of GridListControl, the selection will be automatically set.    
So if you want to set the selection on first item when typed any value on ComboBox, add the first row of GridListControl to Selections. Please make use of the below code example,   
 
Code example:   
void comboDropDown1_TextChanged(object sender, EventArgs e)   
{   
    this.gridListControl1.DataSource = countries;   
    this.comboDropDown1.DroppedDown = true;   
    if (this.gridListControl1.Items.Count != 0)   
    {   
        this.gridListControl1.Grid.Model.Selections.Add(GridRangeInfo.Row(1));   
    }   
}   
  
Sample link   
    
Note:   
If you want to get the selected item, use the selection range of that selected rows. Please refer to below code example,   
Code example:   
        //Get the selected item.   
        int row = this.gridListControl1.Grid.Model.Selections.Ranges[0].Top;   
        DataRowView selectedItem = this.gridListControl1.Items[row - 1] as DataRowView;  
 
 
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.

Warning Icon 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.Close Icon

;