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

Removing a tile from code behind

1 Answer 12 Views
TileList
This is a migrated thread and some comments may be shown as answers.
Conrad
Top achievements
Rank 1
Conrad asked on 23 Aug 2018, 02:14 PM

Hi,

Is it possible to remove a tile from a TileList dynamically? I have tried the code below to remove all delected tiles when the del key is pressed but I get an exception calling Items.Remove()

        private void OnKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Delete)
            {
                foreach (var item in tiledDashboardTileList.SelectedItems)
                {
                    tiledDashboardTileList.Items.Remove(item);
                }
                tiledDashboardTileList.SelectedItems.Clear();
                e.Handled = true;
            }
        }

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 28 Aug 2018, 12:22 PM
Hello Conrad,

This would be expected when manipulating the Items collection of the control in such manner. Instead, you can access its bound source collection and remove the given item from it. This can be achieved through various approaches. For example, you can use the DataContext of the control as follows.
private void tileList_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Delete)
            {
                foreach (Club item in tileList.SelectedItems)
                {
                    (tileList.DataContext as MyViewModel).Clubs.Remove(item);
                }
                tileList.SelectedItems.Clear();
                e.Handled = true;
            }
        }

Can you please give the approach a try?

I hope it helps.

Regards,
Stefan
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
TileList
Asked by
Conrad
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or