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

How to set grid bound data grid columns As a Auto complete in sync fusion in c#

Hi Viewers,

Here I am trying to set  grid  bound data grid  column as a Auto complete how i can do give me guidance please 
(here grid  bound data grid having 5 columns Among those columns Column 1 i need to set as a Auto complete )


thank in Advance 





5 Replies

NK Neelakandan Kannan Syncfusion Team May 27, 2014 12:52 PM UTC

Hi Venkaiah,

 

Thanks for your interest in Syncfusion Products.

 

Query:

Auto complete

 

We would like to let you know that the reported scenario can be achieved by assigning ComboBox celltype type to that particular column.


Please refer the following UG link.

 

http://help.syncfusion.com/ug/windows%20forms/grid/default.htm#!Documents/autocompletesupportf.htm
 


Please let us know if you have any concerns.

 

Regards,

Neelakandan

 



RK Revathi K Syncfusion Team May 29, 2014 05:04 AM UTC

From: venky star [mailto:venkystr5@gmail.com]
Sent: Thursday, May 29, 2014 12:02 AM
To: Syncfusion Support
Subject: Re: Syncfusion support community forum 116433, How to set grid bound data grid columns As a Auto complete in sync fusion in c#, has been updated.

 

Hi Viewer,

 

 Your answer is use full for Data bound data grid columns once As a Combo box its possible to set Auto complete easily, But What i am asking is In Data bound data grid having text box/(original text box)  default right so that  column i need to set as a Auto complete  So please  give me guidance for this task.

 

 

 

thank you in Advance 



NK Neelakandan Kannan Syncfusion Team June 4, 2014 04:39 AM UTC

Hi Venkaiah,

 

Thanks for your updates.

 

 

 

 

Query

Auto Complete Text Box in GridControl

 

 

 

       ShowButtons property ensures  that  show or hide  the cell button in Grid. So, If we set this property to hide, we can display combo box cell as a text box.

         AutoCompleteInEditMode Property ensures  that enabling auto complete. So, You can make use of below code,

 

CODESNIPPET[C#]:

 

private void Form1_Load(object sender, EventArgs e)

        {

            AutoCompleteStringCollection stringcol=new AutoCompleteStringCollection();

            stringcol.Add("One");

            stringcol.Add("Two");

            stringcol.Add("Three");

            this.gridControl1[1, 1].CellType = GridCellTypeName.ComboBox;

            this.gridControl1[1, 1].DataSource = stringcol;

            gridControl1[1,1].DropDownStyle = GridDropDownStyle.Editable;

            gridControl1[1, 1].AutoCompleteInEditMode = GridComboSelectionOptions.AutoComplete;

            gridControl1[1, 1].ShowButtons = GridShowButtons.Hide;

 

   }

 

 

Please let us know if you have any concerns,

 

Regards,

Neelakandan



MR Mukesh Rebari November 29, 2016 03:51 PM UTC

HI,

 Ok, So if we decide to use Combobox then also tell us how could we assign DataSource for Combobox dynamically i.e. filtered data in datasource based on what user has typed in.


PM Piruthiviraj Malaimelraj Syncfusion Team November 30, 2016 12:27 PM UTC

Hi Mukesh, 

Thanks for the update. 

We have analyzed your scenario and created the simple sample as per your requirement. By default, particular cell style cannot be changed at run time for the GridDataBoundGrid without using QueryCellInfo event. So the datasource of the particular cell cannot be changed on run time. 

In order to change the data source of the ComboBoxCell based on the text typed in the cell dynamically, custom cell renderer and cell model which is derived fromComboBoxCellRenderer and ComboBoxCellModel can be used. 

Code example: 

//Adding cellmodel 
this.gridDataBoundGrid1.Model.CellModels.Add("CustomComboBox", new CustomComboxBoxCellModel(this.gridDataBoundGrid1.Model)); 
//Assigning CellType 
this.gridDataBoundGrid1.Model.ColStyles["Description"].CellType = "CustomComboBox"; 
 
public class CustomComboxBoxCellModel : GridComboBoxCellModel 
{ 
    public CustomComboxBoxCellModel(GridModel grid) 
        : base(grid) 
    { 
    } 
    /// <summary> 
    /// Creates a cell renderer. 
    /// </summary> 
    /// <param name="control">The grid control.</param> 
    /// <returns>Cell renderer.</returns> 
    public override GridCellRendererBase CreateRenderer(GridControlBase control) 
    { 
        return new CustomComboBoxCellRenderer(control, this); 
    } 
} 
 
public class CustomComboBoxCellRenderer : GridComboBoxCellRenderer 
{ 
    GridStyleInfo cellStyle = null; 
 
    public CustomComboBoxCellRenderer(GridControlBase grid, GridCellModelBase cellModel) 
        : base(grid, cellModel) 
    { 
        cellStyle = GridStyleInfo.Default; 
    } 
    Hashtable styleCollection = new Hashtable(); 
 
    protected override void OnSetControlText(string text) 
    { 
        if (text == "Desc6") 
        { 
            if (!styleCollection.ContainsKey(GridRangeInfo.Cell(this.RowIndex, this.ColIndex))) 
            { 
                GridStyleInfo style = GridStyleInfo.Empty; 
                style.CopyFrom(this.StyleInfo); 
                DataTable table = new DataTable(); 
                table.Columns.Add("Description"); 
                table.Columns.Add("Desc_ID"); 
                table.Rows.Add("Desc1", 1); 
                table.Rows.Add("Desc2", 2); 
                table.Rows.Add("Desc3", 3); 
                style.DataSource = table.DefaultView; 
 
                style.DisplayMember = "Description"; 
                style.ValueMember = "Desc_ID"; 
 
                styleCollection.Add(GridRangeInfo.Cell(this.RowIndex, this.ColIndex), style); 
            } 
        } 
 
        base.OnSetControlText(text); 
    } 
 
    protected override void OnKeyPress(KeyPressEventArgs e) 
    { 
        this.Grid.CurrentCell.ShowDropDown(); 
        base.OnKeyPress(e); 
    } 
 
    public override void OnPrepareViewStyleInfo(GridPrepareViewStyleInfoEventArgs e) 
    { 
        base.OnPrepareViewStyleInfo(e); 
 
        if (styleCollection.Contains(GridRangeInfo.Cell(e.RowIndex, e.ColIndex))) 
        { 
            GridStyleInfo modifiedStyle = ((GridStyleInfo)styleCollection[GridRangeInfo.Cell(e.RowIndex, e.ColIndex)]); 
            e.Style.DataSource = modifiedStyle.DataSource; 
            e.Style.DisplayMember = modifiedStyle.DisplayMember; 
            e.Style.ValueMember = modifiedStyle.ValueMember; 
        } 
    } 

} 

Please refer to the below KB , 

https://www.syncfusion.com/kb/6951/how-to-change-the-datasource-for-combobox-cell-dynamically  

Sample link: 

http://www.syncfusion.com/downloads/support/forum/116433/ze/GDBG_Sample1683522447 

Regards, 
Piruthiviraj 


SIGN IN To post a reply.
Loader.
Live Chat Icon For mobile
Up arrow icon