Custom SimpleListViewVisualItem (as a container of RadGridView)

2 posts, 0 answers
  1. Gleb
    Gleb avatar
    2 posts
    Member since:
    Oct 2011

    Posted 27 Oct 2011 Link to this post

    I'm developing custom SimpleListViewVisualItem for RadListView. It should contain a list of business items and it should be displayed on RadListView in IconView mode. Business items must be displayed on RadGridView.

    public class CustomVisualItem : SimpleListViewVisualItem
    {
         RadGridView gwBusinessItems;
         BindingSource bsBusinessItems;
         List<BO> _list = new List<BO>();
         ...
         public CustomVisualItem()
         {
              bsBusinessItems.DataSource = _list;
              gwBusinessItems.DataSource = bsBusinessItems;
         }
         ...
         public void InitializeControls()
         {
              gwBusinessItems = new RadGridView();
              gwBusinessItems.Dock = DockStyle.Fill;
              gwBusinessItems.DataSource = bsBusinessItems;
              ...
              Children.Add(gwBusinessItems.GridViewElement);
           }
           ...
            public void AddBO(BO bo)
            {
                _list.Add(bo);
                bsBusinessItems.ResetBindings(false);
            }
    }

    When i add a business object and update RadGridView by bsBusinessItems.ResetBindings, new record appears on the RadGridView, but i'm unable to select any record on the RadGridView and when i click on the grid, GotFocus event isn't fired. Looks like i can't set focus to the grid due to it is on the CustomVisualItem. 

    gwBusinessItems.Focusable = true doesn't work.

    What should i do to make RadGridView focusable? 
  2. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 28 Oct 2011 Link to this post

    Hello Gleb,

    Thank you for your question.

    In order to be able to select grid rows, you need to redirect mouse input from the parent RadListView to the corresponding child RadGridView. The following code demonstrates this:
    this.radListView1.MouseDown += new MouseEventHandler(radListView1_MouseDown);
     
    void radListView1_MouseDown(object sender, MouseEventArgs e)
    {
        RadElement item = this.radListView1.ElementTree.GetElementAtPoint(e.Location);
     
        while (item != null && !(item is CustomLVVisualItem))
        {
            item = item.Parent;
        }
     
        if (item != null)
        {
            ((CustomLVVisualItem)item).GridView.GridBehavior.OnMouseDown(e);
        }
    }

    However, RadGridView is not designed to work this way and this scenario is not supported, so you might experience further difficulties. If more people request the same functionality, we may plan to improve RadListView and RadGridView to support such scenarios in a future release .

    I hope this helps.

    Best wishes,
    Ivan Todorov
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top