this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo);
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
if (e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell
|| e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell)
{
if (e.TableCellIdentity.Column.MappingName == "B")
{
int cellvalue = Convert.ToInt32(e.Style.CellValue);
if (cellvalue < 0)
{
e.Style.BackColor = Color.Red;
e.Style.Format = "{#,##}"; // You can set your own format
}
}
}
}
Hi Fred,
Thank you for your interest in Syncfusion products.
Here is the minimal sample which shows you how to add AutoComplete in GridGroupingControl Cell.
http://websamples.syncfusion.com/samples/grid.windows/I76148Aug29/main.htm
Please let me know if this helps.
Best Regards,
Srirajan.
Hi Customer,
Thanks for your update.
We have provided the sample for TextBox with AutoComplete property. Please find the below attached sample,
Sample link: http://www.syncfusion.com/downloads/support/forum/76148/ze/AutoCompleteTextBox1148621484Please let us know if you need any further assistance.
Regards,Arulpriya
Query |
Response |
how I use BindingSource instead of ChoiceList, I try gridGroupingControl1.TableDescriptor.Columns["Note"] .Appearance.AnyRecordFieldCell.DataSource = SomeBindingSource, but not working |
The DataSource is set as binding source and the data are binds to the column. Please refer the attached video.
Can you please provide the below details which will help us to analyze further and provide you a better solution.
The AutoSuggestion will have the support only for the below DataSources
So, if you are setting the DataSource as BindibingSource, Please ensure that the datasource of the Binding source should be DataTable or ArrayList.
We have modified the sample as per your requirement. Set the BindingSource.DataSource as DataSource for the Column to set the AutoSuggestTextBox column. Please make use of below code and sample,
gridGroupingControl1.TableDescriptor.Columns["ID"].Appearance.AnyRecordFieldCell.DataSource = bindingSource.DataSource; |
gridGroupingControl1.TableDescriptor.Columns["Note"] .Appearance.AnyRecordFieldCell.AutoCompleteInEditMode = GridComboSelectionOptions.AutoSuggest; : it do not show the list when I type |
The DropDown will not be opened when the ComboBox button is hidden. The AutoSuggestion will be shown only when the DropDown is opened. In order to open the DropDown on KeyPress, the CurrentCellKeyPress event can be used. In that event, ShowDropDown() method can be used to open the DropDown. Please make use of below code and sample,
//Event triggering
gridGroupingControl1.TableControlCurrentCellKeyPress += GridGroupingControl1_TableControlCurrentCellKeyPress;
//Event customization
private void GridGroupingControl1_TableControlCurrentCellKeyPress(object sender, GridTableControlKeyPressEventArgs e)
{
if (this.gridGroupingControl1.TableControl.CurrentCell.Renderer is GridComboBoxCellRenderer)
this.gridGroupingControl1.TableControl.CurrentCell.ShowDropDown();
} |
Query |
Response |
Case sensitive : if list contains capital character and I type lowercase character, grid will not filter
|
In order to set a AutoComplete TextBox as Case-insensitive, the TableConrolCurrentCellKeyPress and TableControlCurrentCellKeyUp events can be used. Please make use of below code and sample,
//Event Triggering
this.gridGroupingControl1.TableControlCurrentCellKeyPress += gridGroupingControl1_TableControlCurrentCellKeyPress;
//Event Customization
void gridGroupingControl1_TableControlCurrentCellKeyPress(object sender, GridTableControlKeyPressEventArgs e)
{
GridCurrentCell currentCell = e.TableControl.CurrentCell;
GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(currentCell.RowIndex, currentCell.ColIndex);
if (style.CellType == "ComboBox")
{
GridComboBoxCellRenderer renderer = currentCell.Renderer as GridComboBoxCellRenderer;
if (renderer.ControlText == string.Empty)
{
text = e.Inner.KeyChar.ToString();
}
if (renderer.ControlText != string.Empty)
{
text = renderer.ControlText + e.Inner.KeyChar;
}
rowFilterText = "[" + dataTable.Columns[dataTable.Columns[style.DisplayMember].Ordinal].ColumnName + "]" + " LIKE '" + "%" + text + "%'";
listDataView = new DataView(this.dataTable, rowFilterText, null, DataViewRowState.CurrentRows);
if (listDataView.Count > 0)
{
renderer.ListBoxPart.DataSource = listDataView;
currentCell.ShowDropDown();
}
}
}
//Event Triggering
this.gridGroupingControl1.TableControlCurrentCellKeyUp += gridGroupingControl1_TableControlCurrentCellKeyUp;
//Event customization
void gridGroupingControl1_TableControlCurrentCellKeyUp(object sender, GridTableControlKeyEventArgs e)
{
GridCurrentCell currentCell = e.TableControl.CurrentCell;
GridTableCellStyleInfo style = e.TableControl.GetTableViewStyleInfo(currentCell.RowIndex, currentCell.ColIndex);
if (style.CellType == "ComboBox")
{
GridComboBoxCellRenderer renderer = currentCell.Renderer as GridComboBoxCellRenderer;
if (renderer.ControlText == string.Empty)
{
renderer.ListBoxPart.DataSource = dataTable;
}
}
}
|
If I choose value (eg. A0) and leave cell, come back cell and type different character (eg. B or C), grid will not filter until I delete all and type again |
We have created a simple sample as per your requirement. In order to display the suggested values as per your scenario, CustomComboBoxCellModel and CustomComboBoxCellRenderer can be created. In CustomComboBoxCellRenderer the OnKeyPress method can be overridden to filter the values on key press (i.e. as per your scenario). Please make use of below code and sample,
//To suggest the the values on key press
public class CustomComboBoxCellRenderer : GridComboBoxCellRenderer
{
public CustomComboBoxCellRenderer(GridControlBase grid, GridCellModelBase cellModel)
: base(grid, cellModel)
{
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (this.StyleInfo.DropDownStyle == GridDropDownStyle.Editable
&& this.StyleInfo.AutoCompleteInEditMode == GridComboSelectionOptions.AutoSuggest)
{
ControlText = TextBox.Text.Remove(TextBox.SelectionStart, TextBox.SelectionLength);
base.OnKeyPress(e);
}
}
}
|
protected override void OnKeyPress(KeyPressEventArgs e)
{
CurrentCell.ShowDropDown();
if (this.StyleInfo.DropDownStyle == GridDropDownStyle.Editable
&& this.StyleInfo.AutoCompleteInEditMode == GridComboSelectionOptions.AutoSuggest)
{
ControlText = TextBox.Text.Remove(TextBox.SelectionStart, TextBox.SelectionLength);
SetSuggestedChoices(ListBoxPart, this.ControlText + e.KeyChar.ToString());
}
ListBoxPart.SelectedIndex = 0;
}
internal void SetSuggestedChoices(ListBox listBoxPart, string searchText)
{
…….
…….
}
private void GetlistFromTable(ListBox listBoxPart, string searchText, object dataSource)
{
…..
…..
}
private void GetlistFromArray(ListBox listBoxPart, string searchText, object dataSource)
{
ArrayList arrayList = (ArrayList)dataSource;
IList list = (IList)arrayList;
List<string> intList = new List<string>();
List<string> clist = new List<string>();
string colName = listBoxPart.DisplayMember;
listBoxPart.DataSource = null;
listBoxPart.DisplayMember = colName;
listBoxPart.Items.Clear();
foreach (object item in list)
{
//If any null item found, all the successive items will be skipped from adding it to list.
if (item == null)
break;
ListBoxPart.Items.Add(item);
clist.Add(item.ToString());
}
listBoxPart.Items.Clear();
foreach (string s in clist)
{
if (s.ToLower().Contains(searchText.ToLower()))
listBoxPart.Items.Add(s);
}
} |
Hi,
It's working. Thanks for your great help and patience.
Regards