AutoComplte Combobox
Hello Everyone,
I have one auto complete combobox in one windows form.The combobox is filled by calling a web service method which returns a data set.Now the requirement is that "Select" word should be selected in the dropdown initially when the screen loads.After that if the user changes the selection,then also "Select" should be the first entry in the dropdown(i.e when you open the dropdown with mouse,"Select" should be the first entry).Requirement number 2 is that all the items in the combobox should be sorted according alphabatically.
I have the same requirement for another combobox which is a normal windows combobox.
What I did is that I added one column named "SortBy" to the the datatable.Then I iterated throgh all the rows in the table and set the value of this column as 0 for the row containg "Select".All other rows have been set as 1 for this column.After that I sorted the rows in the dataview using
dsTemplate.Tables[0].DefaultView.Sort = "SortBy,description";
What this essentially does is that it sorts the rows on two columns-first on "SortBy" column which brings the row with "Select" as the first row.After that it sorts the records on "WORKGROUP_NAME" column.So I get my expected behaviour in the windows combo.
But the same code is not working in case of syncfusion auto complete combobox.
I have provided both the code snippets here.
Windows ComboBox binding code:
============================
COT.SubscriptionsWS.SubscriptionService ws = new COT.SubscriptionsWS.SubscriptionService();
DataSet dsWorkgroups = new DataSet();
try
{
dsWorkgroups = ws.GetWorkgroups(PartyPlugin.region, 33,
Convert.ToInt32(cmbRelationship.SelectedValue));
DataRow dr = dsWorkgroups.Tables[0].NewRow();
dsWorkgroups.Tables[0].Rows.InsertAt(dr, 0);
dsWorkgroups.Tables[0].Rows[0]["WORKGROUP_NAME"] = "Select";
dsWorkgroups.Tables[0].Rows[0]["WORKGROUP_ID"] = -1;
dsWorkgroups.Tables[0].Columns.Add("SortBy", typeof(int));
foreach (DataRow ldrSort in dsWorkgroups.Tables[0].Rows)
{
if (ldrSort["WORKGROUP_NAME"].ToString() == "Select")
ldrSort["SortBy"] = 0;
else
ldrSort["SortBy"] = 1;
}
dsWorkgroups.Tables[0].DefaultView.Sort = "SortBy, WORKGROUP_NAME";
cmbWorkGroup.DataSource = dsWorkgroups.Tables[0].DefaultView;
cmbWorkGroup.DisplayMember = "WORKGROUP_NAME";
cmbWorkGroup.ValueMember = "WORKGROUP_ID";
cmbWorkGroup.SelectedIndex = 0;
}
catch (Exception e_)
{
Debug.WriteLine(e_.Message);
}
Syncfusion autocomplte combobox binding code:
==============================================
DataRow[] drArr = dsTemplate.Tables[0].Select("description='Select'");
if (drArr != null && drArr.Length == 0)
{
DataRow dr = dsTemplate.Tables[0].NewRow();
dr["code_value_id"] = "-1";
dr["code"] = "-1";
dr["description"] = "Select";
dr["override_flag"] = "N";
dsTemplate.Tables[0].Rows.InsertAt(dr,0) ;
}
dsTemplate.Tables[0].Columns.Add("SortBy", typeof(int));
foreach (DataRow ldrSort in dsTemplate.Tables[0].Rows)
{
if (ldrSort["description"].ToString() == "Select")
ldrSort["SortBy"] = 0;
else
ldrSort["SortBy"] = 1;
}
dsTemplate.Tables[0].DefaultView.Sort = "SortBy,description";
cmbTemplate.AutoCompleteControl.DataSource = dsTemplate.Tables[0].DefaultView ;
cmbTemplate.DisplayMember = dsTemplate.Tables[0].Columns[2].ColumnName;
cmbTemplate.ValueMember = dsTemplate.Tables[0].Columns[1].ColumnName;
cmbTemplate.Text = "Select";
Prompt response from anyone will be appreciated.
I have one auto complete combobox in one windows form.The combobox is filled by calling a web service method which returns a data set.Now the requirement is that "Select" word should be selected in the dropdown initially when the screen loads.After that if the user changes the selection,then also "Select" should be the first entry in the dropdown(i.e when you open the dropdown with mouse,"Select" should be the first entry).Requirement number 2 is that all the items in the combobox should be sorted according alphabatically.
I have the same requirement for another combobox which is a normal windows combobox.
What I did is that I added one column named "SortBy" to the the datatable.Then I iterated throgh all the rows in the table and set the value of this column as 0 for the row containg "Select".All other rows have been set as 1 for this column.After that I sorted the rows in the dataview using
dsTemplate.Tables[0].DefaultView.Sort = "SortBy,description";
What this essentially does is that it sorts the rows on two columns-first on "SortBy" column which brings the row with "Select" as the first row.After that it sorts the records on "WORKGROUP_NAME" column.So I get my expected behaviour in the windows combo.
But the same code is not working in case of syncfusion auto complete combobox.
I have provided both the code snippets here.
Windows ComboBox binding code:
============================
COT.SubscriptionsWS.SubscriptionService ws = new COT.SubscriptionsWS.SubscriptionService();
DataSet dsWorkgroups = new DataSet();
try
{
dsWorkgroups = ws.GetWorkgroups(PartyPlugin.region, 33,
Convert.ToInt32(cmbRelationship.SelectedValue));
DataRow dr = dsWorkgroups.Tables[0].NewRow();
dsWorkgroups.Tables[0].Rows.InsertAt(dr, 0);
dsWorkgroups.Tables[0].Rows[0]["WORKGROUP_NAME"] = "Select";
dsWorkgroups.Tables[0].Rows[0]["WORKGROUP_ID"] = -1;
dsWorkgroups.Tables[0].Columns.Add("SortBy", typeof(int));
foreach (DataRow ldrSort in dsWorkgroups.Tables[0].Rows)
{
if (ldrSort["WORKGROUP_NAME"].ToString() == "Select")
ldrSort["SortBy"] = 0;
else
ldrSort["SortBy"] = 1;
}
dsWorkgroups.Tables[0].DefaultView.Sort = "SortBy, WORKGROUP_NAME";
cmbWorkGroup.DataSource = dsWorkgroups.Tables[0].DefaultView;
cmbWorkGroup.DisplayMember = "WORKGROUP_NAME";
cmbWorkGroup.ValueMember = "WORKGROUP_ID";
cmbWorkGroup.SelectedIndex = 0;
}
catch (Exception e_)
{
Debug.WriteLine(e_.Message);
}
Syncfusion autocomplte combobox binding code:
==============================================
DataRow[] drArr = dsTemplate.Tables[0].Select("description='Select'");
if (drArr != null && drArr.Length == 0)
{
DataRow dr = dsTemplate.Tables[0].NewRow();
dr["code_value_id"] = "-1";
dr["code"] = "-1";
dr["description"] = "Select";
dr["override_flag"] = "N";
dsTemplate.Tables[0].Rows.InsertAt(dr,0) ;
}
dsTemplate.Tables[0].Columns.Add("SortBy", typeof(int));
foreach (DataRow ldrSort in dsTemplate.Tables[0].Rows)
{
if (ldrSort["description"].ToString() == "Select")
ldrSort["SortBy"] = 0;
else
ldrSort["SortBy"] = 1;
}
dsTemplate.Tables[0].DefaultView.Sort = "SortBy,description";
cmbTemplate.AutoCompleteControl.DataSource = dsTemplate.Tables[0].DefaultView ;
cmbTemplate.DisplayMember = dsTemplate.Tables[0].Columns[2].ColumnName;
cmbTemplate.ValueMember = dsTemplate.Tables[0].Columns[1].ColumnName;
cmbTemplate.Text = "Select";
Prompt response from anyone will be appreciated.
SIGN IN To post a reply.
1 Reply
AD
Administrator
Syncfusion Team
April 2, 2009 06:25 AM UTC
Hi Subrata,
Thank you for using Syncfusion products.
If you want to sort the particular column in autocomplete , you can set them as MatchingColumn.
Please refer the sample below in which the column 'Name' used as MatchingColumn. In the sample 'Markus' selected in the dropdown initially when the application loads. if the user changes the selection 'Markus' will be the first entry in the dropdown.
Here is the sample that demonstrates this.
http://files.syncfusion.com/support/Tools.Windows/7.1.0.30/F80311/Tools_WF_Autocomplete_comboBox.zip
Please let me know if this helps you.
Regards,
Jaya
Thank you for using Syncfusion products.
If you want to sort the particular column in autocomplete , you can set them as MatchingColumn.
Please refer the sample below in which the column 'Name' used as MatchingColumn. In the sample 'Markus' selected in the dropdown initially when the application loads. if the user changes the selection 'Markus' will be the first entry in the dropdown.
Here is the sample that demonstrates this.
http://files.syncfusion.com/support/Tools.Windows/7.1.0.30/F80311/Tools_WF_Autocomplete_comboBox.zip
Please let me know if this helps you.
Regards,
Jaya
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
SD Subrata Das
- Mar 29, 2009 03:48 PM UTC
- Apr 2, 2009 06:25 AM UTC