Windows Form Designer can't handle custom components

I have a custom list view created by extending the ListView Class and the Forms Designer in Rider says : "Window forms designer exception: Could not find type 'Project1.ListViewWithReordering'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built using settings for your current platform or Any CPU.. Line: 24".

ListViewWithReording is an extension of ListView but I had to go into Visual Studio to edit the form. Is there a way to make it so Rider can recognize it? Maybe I am missing some necessary code in the class for Rider.

Any pointers would be appreciated.

0
4 comments

Hi @...

Thank you for your request. What version of Rider do you use?

Could you please attach a sample code part or solution so we could double-check the issue on our side?

Thank you in advance! 

0

I am using the latest version Rider, 2021.1.3. The class in question is below.

- Steve

using System.Drawing;
using System.Windows.Forms;

namespace Form1
{
/// <summary>
/// A ListView with DragDrop reordering.
/// <see cref="http://support.microsoft.com/kb/822483/en-us" />
/// </summary>
internal sealed class ListViewWithReordering : ListView
{
protected override void OnItemDrag(ItemDragEventArgs e)
{
base.OnItemDrag(e);
//Begins a drag-and-drop operation in the ListView control.
DoDragDrop(SelectedItems, DragDropEffects.Move);
}

protected override void OnDragEnter(DragEventArgs drgevent)
{
base.OnDragEnter(drgevent);
var len = drgevent.Data.GetFormats().Length - 1;
int i;
for (i = 0; i <= len; i++) {
if (drgevent.Data.GetFormats()[i].Equals("System.Windows.Forms.ListView+SelectedListViewItemCollection")) {
//The data from the drag source is moved to the target.
drgevent.Effect = DragDropEffects.Move;
}
}
}

protected override void OnDragDrop(DragEventArgs drgevent)
{
base.OnDragDrop(drgevent);
//Return if the items are not selected in the ListView control.
if (SelectedItems.Count == 0) {
return;
}
//Returns the location of the mouse pointer in the ListView control.
var cp = PointToClient(new Point(drgevent.X, drgevent.Y));
//Obtain the item that is located at the specified location of the mouse pointer.
ListViewItem dragToItem = GetItemAt(cp.X, cp.Y);
if (dragToItem == null) {
return;
}
//Obtain the index of the item at the mouse pointer.
var dragIndex = dragToItem.Index;
ListViewItem[] sel = new ListViewItem[SelectedItems.Count];
for (var i = 0; i <= SelectedItems.Count - 1; i++) {
sel[i] = SelectedItems[i];
}
for (var i = 0; i < sel.GetLength(0); i++) {
//Obtain the ListViewItem to be dragged to the target location.
ListViewItem dragItem = sel[i];
var itemIndex = dragIndex;
if (itemIndex == dragItem.Index) {
return;
}
if (dragItem.Index < itemIndex) {
itemIndex++;
} else {
itemIndex = dragIndex + i;
}
//Insert the item at the mouse pointer.
ListViewItem insertItem = (ListViewItem) dragItem.Clone();
Items.Insert(itemIndex, insertItem);
//Removes the item from the initial location while
//the item is moved to the new location.
Items.Remove(dragItem);
}
}
}
}







 

0

At some point - not always - the same applies to User Controls.The Form Designer was unable to open, producing the same error. In VS I had no problem.

0

Hello @...

Please accept my apologies for the delay. 

Unfortunately, I was not able to reproduce the issue in my environment with a small test project. 

I'd like to ask you to try the latest EAP and check if the issue still persists. In this case, please, create a new issue with `Help | Report a bug` with automatically added logs so we could analyze them. 

Thank you in advance! 

0

Please sign in to leave a comment.