CUSTOM LIST DROPDOWNLIST

13 posts, 1 answers
  1. Bruno
    Bruno avatar
    7 posts
    Member since:
    May 2013

    Posted 29 Dec 2015 Link to this post

    In my project I need change checkboxes for button in CheckedDropDownList  or add buttons in DropDownList. It's possible?
  2. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 29 Dec 2015 Link to this post

    Hello Bruno,

    Thank you for writing.
     
    Please refer to the DropDownList >> Custom Items help article which demonstrates a sample approach how to create custom items. Thus, you can add a StackLayoutElement that contains a RadButtonElement and a LightVisualElement for the text.

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Bruno
    Bruno avatar
    7 posts
    Member since:
    May 2013

    Posted 29 Dec 2015 in reply to Dess Link to this post

    Dess

     thanks for the fast answer. But I have 2 question:

    - how I insert new RadListDataItem with new fields that I create? In the exemple how I insert the Anddress, Phone, because I dont see where is insert new data .

    - Where I insert the code for put a button in the list

     

    Obs: Forgive my english, I'm not good writer 

     

  5. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 29 Dec 2015 Link to this post

    Hello Bruno,

    Thank you for writing back.

    As it is noted in the referred article, it demonstrates how to display detailed information for each employee from the Northwind.Employees table which is used as data source. Thus, in the RadListVisualItem.Synchronize method, the relevant data is filled in the custom elements considering the DataBoundItem.

    Following the approach from the help article, I have prepared  a sample project for your convenience with a RadButtonElement. The result is illustrated on the attached screenshot.

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Bruno
    Bruno avatar
    7 posts
    Member since:
    May 2013

    Posted 29 Dec 2015 in reply to Dess Link to this post

    Dress

     We are almost there! Its remais only doubt.

    - I use a List to populate my new DropDown and I change the code "Synchronize" to use my List, however I can not select itens in my list. I atteched a imagem of my object.

     What I need change for work with my list and select one of list itens? and why show the name of may class in my new object

     

            public override void Synchronize()
            {
                base.Synchronize();
                this.Text = string.Empty;
                clDDLEWT rowView = this.Data.DataBoundItem as clDDLEWT;
                if (rowView != null)
                {
                    //this.photoElement.Image = GetImageFromData(rowView.Row["Photo"] as byte[]);
                    this.titleElement.Text = rowView.Title;
                    this.nameElement.Text = rowView.FirstName+ " oi " + rowView.LastName.ToString();
                    this.addressElement.Text = "Address: " + rowView.Address;
                    this.phoneElement.Text = "Phone: " + rowView.HomePhone;
                }
            }

     

    It remains only doubt
    It remains only doubt
  7. Bruno
    Bruno avatar
    7 posts
    Member since:
    May 2013

    Posted 29 Dec 2015 in reply to Bruno Link to this post

    Dess,

     I got it. Forget thank for your help.

    I had forgotten to declare "DisplayMember".

     thanks again and happy new year!!

     

    I had forgotten
  8. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 30 Dec 2015 Link to this post

    Hello Bruno,

    Thank you for writing back.

    I am glad that the problem you were facing is now resolved. Note that data binding is a mechanism for automatic population of the RadDropDownList with items, based on the provided data structure. Three properties control the data binding:
    • DataSource - specifies the data structure to be bound.
    • DisplayMember - specifies the particular field in the data source which will be used from the items in RadDropDownList for their Text.
    • ValueMember - specifies the particular field in the data source which will be stored in the items' Value property.
    Additional information is available at the following link: http://www.telerik.com/help/winforms/dropdown-and-listcontrol-dropdownlist-populating-with-data-data-binding.html
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  9. Bruno
    Bruno avatar
    7 posts
    Member since:
    May 2013

    Posted 30 Dec 2015 Link to this post

    Dess,

    How I consume button_click in my project? I want get ValueMember selected and return when the user click in the button. I belive that I should use delegate but I dont know how acces in my mainproject

  10. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 30 Dec 2015 Link to this post

    Hello Bruno,

    Thank you for writing back.

    Here is a sample code snippet demonstrating how to subscribe to the RadButtonElement.Click event and access the Value associated with the Data item:
    public Form1()
    {
        InitializeComponent();
        this.radDropDownList1.CreatingVisualListItem += radDropDownList1_CreatingVisualListItem;
        this.radDropDownList1.DataSource = this.employeesBindingSource;
        this.radDropDownList1.DisplayMember = "LastName";
        this.radDropDownList1.ValueMember = "EmployeeID";
        this.radDropDownList1.AutoSizeItems = true;
       
    }
     
    private void radDropDownList1_CreatingVisualListItem(object sender, Telerik.WinControls.UI.CreatingVisualListItemEventArgs args)
    {
        args.VisualItem = new CustomVisualItem();
    }
     
    public class CustomVisualItem : RadListVisualItem
    {
        StackLayoutElement container;
        LightVisualElement textElement;
        RadButtonElement buttonElement;
     
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(RadListVisualItem);
            }
        }
     
        protected override void CreateChildElements()
        {
            base.CreateChildElements();
             
            container = new StackLayoutElement();             
            textElement = new LightVisualElement();
            buttonElement = new RadButtonElement();
            buttonElement.MaxSize = new Size(200, 20);
            buttonElement.Click+=buttonElement_Click;
            this.Children.Add(container);
     
            container.Orientation = Orientation.Horizontal;
     
            container.Children.Add(textElement);
            container.Children.Add(buttonElement);
        }
     
        private void buttonElement_Click(object sender, EventArgs e)
        {
            RadMessageBox.Show(this.Data.Value.ToString());
        }
     
        public override void Synchronize()
        {
            base.Synchronize();
            this.Text = string.Empty;
            DataRowView rowView = this.Data.DataBoundItem as DataRowView;
            if (rowView != null)
            {
                this.textElement.Image = GetImageFromData(rowView.Row["Photo"] as byte[]);
                this.textElement.Text = rowView.Row["FirstName"].ToString() + " " + rowView.Row["LastName"].ToString();
                this.buttonElement.Text = "Phone: " + rowView.Row["HomePhone"].ToString();
            }
        }
     
        private Image GetImageFromData(byte[] imageData)
        {
            const int OleHeaderLength = 78;
            MemoryStream memoryStream = new MemoryStream();
            if (HasOleContainerHeader(imageData))
            {
                memoryStream.Write(imageData, OleHeaderLength, imageData.Length - OleHeaderLength);
            }
            else
            {
                memoryStream.Write(imageData, 0, imageData.Length);
            }
            Bitmap bitmap = new Bitmap(memoryStream);
            return bitmap.GetThumbnailImage(55, 65, null, new IntPtr());
        }
     
        private bool HasOleContainerHeader(byte[] imageByteArray)
        {
            const byte OleByte0 = 21;
            const byte OleByte1 = 28;
            return (imageByteArray[0] == OleByte0) && (imageByteArray[1] == OleByte1);
        }
    }

    I hope this information helps. If you have any additional questions, please let me know.
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  11. Bruno
    Bruno avatar
    7 posts
    Member since:
    May 2013

    Posted 30 Dec 2015 Link to this post

    Dess

     It's possible only in frist item of list insert only textbox, and the follow itens keep the same object (textelement and buttonelement)?

  12. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 04 Jan Link to this post

    Hello

    Thank you for writing back. 

    In the Synchronize method you can control which elements will be visible considering the data item. Here is an example: 
    public override void Synchronize()
    {
        base.Synchronize();
        this.Text = string.Empty;
        DataRowView rowView = this.Data.DataBoundItem as DataRowView;
        if (rowView != null)
        {
            this.textElement.Image = GetImageFromData(rowView.Row["Photo"] as byte[]);
            this.textElement.Text = rowView.Row["FirstName"].ToString() + " " + rowView.Row["LastName"].ToString();
            this.buttonElement.Text = "Phone: " + rowView.Row["HomePhone"].ToString();
     
            if (this.textElement.Text == "Nancy Davolio")
            {
                this.buttonElement.Visibility = ElementVisibility.Collapsed;
            }
            else
            {
                this.buttonElement.Visibility = ElementVisibility.Visible;
            }
        }
    }

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  13. Bruno
    Bruno avatar
    7 posts
    Member since:
    May 2013

    Posted 04 Jan in reply to Dess Link to this post

    Dess

     When I dont knhow who is the first item? Can I use rowindex or something like that?

  14. Answer
    Dess
    Admin
    Dess avatar
    1601 posts

    Posted 04 Jan Link to this post

    Hello Bruno,

    Thank you for writing back. 

    You can use the RadListVisualItem.Data.Index property:
    public override void Synchronize()
    {
        base.Synchronize();
        this.Text = string.Empty;
        DataRowView rowView = this.Data.DataBoundItem as DataRowView;
        if (rowView != null)
        {
            this.textElement.Image = GetImageFromData(rowView.Row["Photo"] as byte[]);
            this.textElement.Text = rowView.Row["FirstName"].ToString() + " " + rowView.Row["LastName"].ToString();
            this.buttonElement.Text = "Phone: " + rowView.Row["HomePhone"].ToString();
     
            if (this.Data.Index == 0)
            {
                this.buttonElement.Visibility = ElementVisibility.Collapsed;
            }
            else
            {
                this.buttonElement.Visibility = ElementVisibility.Visible;
            }
        }
    }

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready