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

Custom SimpleListViewVisualItem (as a container of RadGridView)

1 Answer 189 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Gleb
Top achievements
Rank 1
Gleb asked on 27 Oct 2011, 09:09 AM
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? 

1 Answer, 1 is accepted

Sort by
0
Ivan Todorov
Telerik team
answered on 28 Oct 2011, 12:43 PM
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.

Tags
ListView
Asked by
Gleb
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Share this question
or