Select custom ListView Item

4 posts, 1 answers
  1. Andrey
    Andrey avatar
    2 posts
    Member since:
    Mar 2012

    Posted 12 Mar 2012 Link to this post

    I create new item class
        public class MyCustomVisualItem : SimpleListViewVisualItem
        {
            private LightVisualElement _contentElementName;
            private LightVisualElement _contentElementState;
     
            private StackLayoutPanel _stackLayoutH;
            private StackLayoutPanel _stackLayoutV;
     
            private ImagePrimitive _image1;
            
            protected override void CreateChildElements()
            {
                base.CreateChildElements();
     
                _stackLayoutH = new StackLayoutPanel
                {
                    Orientation = Orientation.Horizontal,
                    EqualChildrenWidth = false
                };
     
                _stackLayoutV = new StackLayoutPanel
                {
                    Orientation = Orientation.Vertical,
                    EqualChildrenWidth = true,
                    Margin = new Padding(10,0,0,0)
                };
     
                _image1 = new ImagePrimitive
                {
                    Image = (Image)Resource1.ResourceManager.GetObject("Anonymous"),
                    Alignment = ContentAlignment.MiddleLeft
                };
                _stackLayoutH.Children.Add(_image1);
     
     
                _contentElementName = new LightVisualElement
                {
                    StretchHorizontally = true,
                    Alignment = ContentAlignment.MiddleLeft,
                    ImageAlignment = ContentAlignment.MiddleLeft,
                    TextAlignment = ContentAlignment.MiddleLeft,
                    Image = (Image)Resource1.ResourceManager.GetObject("Untitled_1s"),
                    TextImageRelation = TextImageRelation.ImageBeforeText
                };
                _stackLayoutV.Children.Add(_contentElementName);
     
                _contentElementState = new LightVisualElement
                {
                    StretchHorizontally = true,
                    Alignment = ContentAlignment.MiddleLeft,
                    TextAlignment = ContentAlignment.MiddleLeft,
                    ForeColor = Color.Gray,
                };
                _stackLayoutV.Children.Add(_contentElementState);
     
                _stackLayoutH.Children.Add(_stackLayoutV);
     
                Children.Add(_stackLayoutH);
            }
     
            protected override void SynchronizeProperties()
            {
                base.SynchronizeProperties();
     
                Text = "";
                _contentElementName.Text = Convert.ToString(Data["Name"]);
                _contentElementState.Text = "Life is Good";
     
            }
     
            protected override Type ThemeEffectiveType
            {
                get
                {
                    return typeof(SimpleListViewVisualItem);
                }
            }
        }

    add to item creating
     	
    	public RadForm1()
            {
                InitializeComponent();
                this.radListView1.Columns.Add("Name");
                this.radListView1.Items.Add(new ListViewDataItem("text"));
                this.radListView1.Items[0]["Name"] = "User";
            }
     
            private void radListView1_VisualItemCreating(object sender, Telerik.WinControls.UI.ListViewVisualItemCreatingEventArgs e)
            {
                e.VisualItem = new MyCustomVisualItem();
            }
     
            private void radListView1_SelectedItemChanged(object sender, EventArgs e)
            {
                int s = 2;
            }
    Action radListView1_SelectedItemChanged in ListView doesn't work when i click on LightVisualElement element in my custom ListView item.
    When click on free space in the item or on ImagePrimitive element all work and selected item changing.
    How can i fix it?
  2. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 14 Mar 2012 Link to this post

    Hi Andrey,

    Thank you for writing.

    In order to allow the LightVisualElement to pass the mouse to its elements tree (thus, change the selected item), you should set the ShouldHandleMouseInput property of both LightVisualElements to false.

    I hope that the provided information addresses your question. If I can be of further assistance, do not hesitate to contact us.

    All the best,
    Stefan
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Andrey
    Andrey avatar
    2 posts
    Member since:
    Mar 2012

    Posted 14 Mar 2012 Link to this post

    Thank you for your reply.
    It helped me a lot.
  5. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 19 Mar 2012 Link to this post

    Hello,

    You are welcome. Should you have any other questions, do not hesitate to contact us.
     
    All the best,
    Stefan
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Back to Top