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

Select custom ListView Item

3 Answers 214 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Andrey
Top achievements
Rank 1
Andrey asked on 12 Mar 2012, 09:41 AM
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?

3 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 14 Mar 2012, 09:59 AM
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 >>
0
Andrey
Top achievements
Rank 1
answered on 14 Mar 2012, 03:06 PM
Thank you for your reply.
It helped me a lot.
0
Stefan
Telerik team
answered on 19 Mar 2012, 09:58 AM
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 >>
Tags
ListView
Asked by
Andrey
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Andrey
Top achievements
Rank 1
Share this question
or