Recommended Telerik Control

4 posts, 0 answers
  1. Jeremie
    Jeremie avatar
    13 posts
    Member since:
    Apr 2011

    Posted 29 Nov 2011 Link to this post

    Telerik Forums,

    The company I work for has a scenario that I'm sure other people have faced.  We have several tables of records that are mainly used as code values, status codes, etc.  Each of these tables has an Active flag so that as old values are no longer needed we can flag them so they aren't displayed to the user.  However, when looking at an older record it is very possible that you would need to populate a value that is now inactive.

    I believe/hope that either the telerik ComboBox or MultiColumnComboBox could assist us with this, I'm envisioning that the ComboBox would load both the active and inactive values and that with a filter applied only the active values would be displayed in the drop down for the user to select on new data entry.

    Does this sound like something that can be achieved with a telerik control?

    Thanks in advance,

    Jeremie
  2. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 02 Dec 2011 Link to this post

    Hi Jeremie,

    Thank you for your question. 

    In our latest release we removed the obsolete RadComboBox control. It is replaced by RadDropDownList. It is easy to apply filtering in RadDropDownList, you should set the Filter property like demonstrated in the following code snippet:
    DataTable table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Name", typeof(string));
     
    table.Rows.Add(0, "zero");
    table.Rows.Add(1, "one");
    table.Rows.Add(2, "two");
    table.Rows.Add(3, "zero");
     
    RadDropDownList list = new RadDropDownList();
    list.Location = new Point(50, 50);
    list.Size = new System.Drawing.Size(200, 20);
    list.DataSource = table;
    list.DisplayMember = "Name";
    list.ValueMember = "ID";
     
    this.Controls.Add(list);
     
    list.Filter = new Predicate<RadListDataItem>(delegate(RadListDataItem item)
    {
        return (int)item.Value == 1;
    });

    I hope this helps. If you have further questions, we will be glad to help.
     
    Kind regards,
    Jack
    the Telerik team

    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jeremie
    Jeremie avatar
    13 posts
    Member since:
    Apr 2011

    Posted 02 Dec 2011 Link to this post

    Jack,

    Thanks for your response.  I did actually discover the Filter property of the DropDownList and it appears to work well.  However it may work a little too well because the filter actually appears to remove the items from the DropDownList's item collection once filtered.

    public partial class Form1 : Form
      {
        public Form1()
        {
          InitializeComponent();
        }
     
        private void Form1_Load(object sender, EventArgs e)
        {
          var modalities = new List<Modality>();
          modalities.Add(new Modality { Active = "N", ModalityCode = "(MODALITY NOT LISTED)", ModalityId = 1 });
          modalities.Add(new Modality { Active = "Y", ModalityCode = "PATIENT MONITORING", ModalityId = 2 });
          modalities.Add(new Modality { Active = "Y", ModalityCode = "DIAGNOSTIC IMAGING", ModalityId = 3 });
     
          radDropDownListModality.DataSource = modalities;
          radDropDownListModality.DisplayMember = "ModalityCode";
          radDropDownListModality.ValueMember = "ModalityId";
          radDropDownListModality.Filter = ActiveFilter;
        }
     
        private bool ActiveFilter(RadListDataItem obj)
        {
          return ((Modality)obj.DataBoundItem).Active == "Y";
        }
     
        private void buttonClickMe_Click(object sender, EventArgs e)
        {
          radDropDownListModality.SelectedValue = 1;
        }
      }
     
      internal class Modality
      {
        public int ModalityId { get; set; }
     
        public string ModalityCode { get; set; }
     
        public string Active { get; set; }
      }

    When you try to assign the SelectedValue of 1 it merely clears the DropDownList selection because 1 isn't in the Items anymore.  Is there a way around this?

    Thanks for the help,

    Jeremie
  5. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 05 Dec 2011 Link to this post

    Hello Jeremie,

    I am not sure that I fully understand your requirements. You can remove the filter by simply setting the Filter property to null. Here is a sample:
    radDropDownListModality.Filter = null;

    Could you please elaborate a bit more and describe what you want to achieve in detail? I will be glad to help further.
     
    Kind regards,
    Jack
    the Telerik team

    Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

Back to Top