This is a migrated thread and some comments may be shown as answers.

Recommended Telerik Control

3 Answers 68 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jeremie
Top achievements
Rank 1
Jeremie asked on 29 Nov 2011, 07:12 PM
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

3 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 02 Dec 2011, 04:38 PM
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.

0
Jeremie
Top achievements
Rank 1
answered on 02 Dec 2011, 04:45 PM
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
0
Jack
Telerik team
answered on 05 Dec 2011, 10:24 AM
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.

Tags
General Discussions
Asked by
Jeremie
Top achievements
Rank 1
Answers by
Jack
Telerik team
Jeremie
Top achievements
Rank 1
Share this question
or