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
close icon

How to avoid anyother text in Combo box cell type

I have a column which is of type ComboBox in a gridgrouping control.

Grid.TableDescriptor.Columns[ABC].Appearance.AnyCell.CellType = "ComboBox";

I have given a choice list for this combo box to choose value from. But I am able to put anyother text in this field.

Is there any settings which can prevent this?

Thanks
Vaibhav

5 Replies

CI Christopher Issac Sunder K Syncfusion Team June 23, 2010 12:15 PM UTC

Hi Vaibhav,

Thank you for your interest in Syncfusion products.

Preventing any other text rather than the choice list of the combo box cell in GridGroupingControl can be achieved by setting the DropDownStyle property to “AutoComplete”.


StringCollection str = new StringCollection();
str.AddRange(year);
this.gridGroupingControl1.DataSource = dt;
this.gridGroupingControl1.TableDescriptor.Columns["Year"].Appearance.AnyRecordFieldCell.CellType = "ComboBox";
this.gridGroupingControl1.TableDescriptor.Columns["Year"].Appearance.AnyRecordFieldCell.ChoiceList = str;
this.gridGroupingControl1.TableDescriptor.Columns["Year"].Appearance.AnyRecordFieldCell.DropDownStyle = Syncfusion.Windows.Forms.Grid.GridDropDownStyle.AutoComplete; // set this to avoid any other text.


Please refer the following sample which illustrates the above.

http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=GGC_AutoComplete284425996.zip

Please let me know if you have any other concerns.

Regards,
Christopher K.


VS Vaibhav Sanghavi June 28, 2010 10:10 AM UTC

Thanks. Works beautifully.

Is there also a way to avoid same drop down value if its already selected in any other record for the same column?

Vaibhav


CI Christopher Issac Sunder K Syncfusion Team June 29, 2010 02:12 PM UTC

Hi Vaibhav,

Thanks for the update.

You could achieve the desired behavior in combo box cell by handling the PrepareViewStyleInfo event with the following code. Here I have created two methods named “IntersectCollection()” and “GetCellValues()” to filter the cell values.


this.gridGroupingControl1.TableControlPrepareViewStyleInfo += new GridTableControlPrepareViewStyleInfoEventHandler(gridGroupingControl1_TableControlPrepareViewStyleInfo);

void gridGroupingControl1_TableControlPrepareViewStyleInfo(object sender, GridTableControlPrepareViewStyleInfoEventArgs e)
{
GridTableCellStyleInfoIdentity id = this.gridGroupingControl1.TableModel[e.Inner.RowIndex, e.Inner.ColIndex].CellIdentity as GridTableCellStyleInfoIdentity; if(id.Column!=null && id.Column.Name.Equals("Year"))
{
e.Inner.Style.ChoiceList = IntersectCollection();
}
}

public StringCollection IntersectCollection()
{
int row, col;
this.gridGroupingControl1.TableDescriptor.ColumnToRowColIndex("Year", out row, out col);

StringCollection str = new StringCollection();
StringCollection s = GetCellValues(col + 1);

if (s.Count > 0)
{
foreach (string st in year)
{
if (!s.Contains(st) && !str.Contains(st))
str.Add(st);
}
}
return str;
}

public StringCollection GetCellValues(int colIndex) // separate the available choices
{
StringCollection str1 = new StringCollection();
if (this.gridGroupingControl1.TableModel.CurrentCellInfo != null)
{
for (int i = 3; i < this.gridGroupingControl1.TableModel.RowCount + 1; i++)
{
string value = "";
if (this.gridGroupingControl1.TableModel[i, colIndex].CellValue != null)
value = this.gridGroupingControl1.TableModel[i, colIndex].CellValue.ToString();
str1.Add(value);
}
}
return str1;
}


Please refer the following sample which illustrates the above.

http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=GGC_Separate528536529.zip

Please let me know if you have any other concerns.

Regards,
Christopher K.


VS Vaibhav Sanghavi June 30, 2010 06:07 AM UTC

Thanks. I was just interested if there is any property which will prevent me selecting any option from choice list whihc has been already selected for other recoreds. But looks like there is none. I already wrote thich check by capturing RecordValueChanging event.



JJ Jisha Joy Syncfusion Team June 30, 2010 10:54 AM UTC

Hi Vaibhav,

Thank you for your update. There is no property setting available to prevent selection of option from choicelist which has been already selected for other records. You need to achieve the desired behavior like one done in the previous update.

Regards,
Jisha

Loader.
Live Chat Icon For mobile
Up arrow icon