3 Answers, 1 is accepted
Could you please paste here the RadComboBox declaration so that we can test your approach at our side and try to find a working solution for you?
Regards,
Nick
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
It is all done in code behind. The rad combo is used as a filter combo for a rad grid. This is based off one of your demos, I just replaced the asp drop down with a rad grid, I needed to be able to change the dropdownlistwidth.
Here is the class I use:
public
class MyCustomFilteringColumn : GridBoundColumn
{
private object listDataSource = null;
int mintWidth = 0;
int mintListWidth = 0;
public int ListWidth
{
get { return mintListWidth; }
set { mintListWidth = value; }
}
public int Width
{
get { return mintWidth; }
set { mintWidth = value; }
}
//RadGrid will call this method when it initializes the controls inside the filtering item cells
protected override void SetupFilterControls(TableCell cell)
{
base.SetupFilterControls(cell);
cell.Controls.RemoveAt(0);
Telerik.Web.UI.
RadComboBox list = new RadComboBox();
//System.Web.UI.WebControls.DropDownList list = new System.Web.UI.WebControls.DropDownList();
list.ID =
"list" + this.DataField.Replace(" ", "_");
list.Height =
Unit.Pixel(250);
list.AutoPostBack =
true;
//list.SelectedIndexChanged += new EventHandler(list_SelectedIndexChanged);
list.SelectedIndexChanged +=
new RadComboBoxSelectedIndexChangedEventHandler(list_SelectedIndexChanged);
cell.Controls.AddAt(0, list);
cell.Controls.RemoveAt(1);
list.DataTextField =
this.DataField;
list.DataValueField =
this.DataField;
list.DataSource =
this.ListDataSource;
list.DataBind();
//list.Font.Size = FontUnit.XXSmall;
list.Style.Add(
"font-size", "0.5em");
list.Font.Name =
"arial";
//if (mintWidth > 0)
//{
list.Width =
Unit.Percentage(97);
//}
list.DropDownWidth =
Unit.Percentage(125);
if (mintListWidth > 0)
{
}
list.Skin =
"Outlook";
}
//void list_SelectedIndexChanged(object sender, EventArgs e)
void list_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
GridFilteringItem filterItem = (sender as RadComboBox).NamingContainer as GridFilteringItem;
this.SelectedValue = (sender as RadComboBox).SelectedValue;
//GridFilteringItem filterItem = (sender as DropDownList).NamingContainer as GridFilteringItem;
//this.SelectedValue = (sender as DropDownList).SelectedValue;
this.FilteredColumnName = this.UniqueName;
if (this.UniqueName == "Index")
{
//this is example for filtering for integer column type
filterItem.FireCommandEvent(
"Filter", new Pair("EqualTo", this.UniqueName));
}
//filtering for string column type
filterItem.FireCommandEvent(
"Filter", new Pair("Contains", this.UniqueName));
}
public void Rebind()
{
}
public object ListDataSource
{
get
{
return this.listDataSource;
}
set
{
listDataSource =
value;
}
}
public string SelectedValue
{
get
{
object res = this.Owner.OwnerGrid.Page.Session["SelectedValue"];
if (res != null)
{
return (string)res;
}
return "";
}
set
{
this.Owner.OwnerGrid.Page.Session["SelectedValue"] = value;
}
}
public string FilteredColumnName
{
get
{
object res = this.Owner.OwnerGrid.Page.Session["FilteredColumnName"];
if (res != null)
{
return (string)res;
}
return "";
}
set
{
this.Owner.OwnerGrid.Page.Session["FilteredColumnName"] = value;
}
}
//RadGrid will call this method when the value should be set to the filtering input control(s)
protected override void SetCurrentFilterValueToControl(TableCell cell)
{
base.SetCurrentFilterValueToControl(cell);
RadComboBox list = (RadComboBox)cell.Controls[0];
//System.Web.UI.WebControls.DropDownList list = (System.Web.UI.WebControls.DropDownList)cell.Controls[0];
if (this.CurrentFilterValue != string.Empty)
{
list.SelectedValue =
this.CurrentFilterValue;
}
}
//RadGrid will call this method when the filtering value should be extracted from the filtering input control(s)
protected override string GetCurrentFilterValueFromControl(TableCell cell)
{
RadComboBox list = (RadComboBox)cell.Controls[0];
//System.Web.UI.WebControls.DropDownList list = (System.Web.UI.WebControls.DropDownList)cell.Controls[0];
return list.SelectedValue;
}
public override GridColumn Clone()
{
return base.Clone();
}
protected override string GetFilterDataField()
{
return this.DataField;
}
}
I suggest that you try setting the DropDownWidth property in pixels instead of Percentages.
list.DropDownWidth = Unit.Pixel(125); Also, you can try using a different Skin and let us known how this goes.
Regards,
Rosi
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
