dotNet Listview control groups not working in maxscript rollout

dotNet Listview control groups not working in maxscript rollout

Anonymous
Not applicable
827 Views
3 Replies
Message 1 of 4

dotNet Listview control groups not working in maxscript rollout

Anonymous
Not applicable
Hi guys,

I'm trying to get a dotNet Listview control to display it's items in groups like if you're in windows explorer (in vista) and choose View >> Group By >> Name for example.

I can get this to work no probs in C#, but when I try and port the code line for line over to maxscript nothing happens.

Here's the designer created C# code:


private void InitializeComponent()
{
System.Windows.Forms.ListViewGroup listViewGroup1 = new System.Windows.Forms.ListViewGroup("Group 01", System.Windows.Forms.HorizontalAlignment.Left);
System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("item 01");
this.myListview = new System.Windows.Forms.ListView();
this.SuspendLayout();
//
// myListview
//
listViewGroup1.Header = "Group 01";
listViewGroup1.Name = "Group 01";
this.myListview.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] {
listViewGroup1});
listViewItem1.Group = listViewGroup1;
this.myListview.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem1});
this.myListview.Location = new System.Drawing.Point(1, 1);
this.myListview.Name = "myListview";
this.myListview.Size = new System.Drawing.Size(289, 179);
this.myListview.TabIndex = 0;
this.myListview.UseCompatibleStateImageBehavior = false;
this.myListview.View = System.Windows.Forms.View.SmallIcon;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(289, 179);
this.Controls.Add(this.myListview);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}

private System.Windows.Forms.ListView myListview;


And here's my maxscript code:


-- Killing the dialog box if it exists
try(destroyDialog KRMU_myRollout); catch()

rollout KRMU_myRollout "my Rollout" width:271 height:199
(
-- ************* LOCALS **************
-- ***********************************

-- *************** UI ****************
-- ***********************************
-- Listview dotNet control
dotNetControl myListview "System.Windows.Forms.ListView" pos: width:268 height:198 enabled:true

-- *********** FUNCTIONS *************
-- ***********************************

-- ********** UI HANDLERS ************
-- ***********************************
on KRMU_myRollout open do
(
-- Listview Group
local listViewGroup1 = dotNetObject "System.Windows.Forms.ListViewGroup" "Group 01" (dotNetClass "System.Windows.Forms.HorizontalAlignment").Left

-- Listview item
local listViewItem1 = dotNetObject "System.Windows.Forms.ListViewItem" "item 01"

-- Listview setup
listViewGroup1.header = "Group 01"
listViewGroup1.name = "Group 01"
myListview.Groups.addRange #(listViewGroup1) -- Could just use groups.add but this is how c# does it
listViewItem1.Group = listViewGroup1
myListview.Items.addRange #(listViewItem1) -- Could just use items.add but this is how c# does it

myListview.Name = "myListview"
myListview.UseCompatibleStateImageBehavior = false
myListview.View = (dotNetClass "System.Windows.Forms.View").SmallIcon

)
)

-- ************** MAIN ***************
-- ***********************************
-- create the rollout window and add the rollout
CreateDialog KRMU_myRollout


I don't get any errors, the listview and item are displayed correctly but the group just doesn't display.

Thanks for any help!

G
0 Likes
828 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Well there is something really screwy going on here. I made myself a custom listview control derived from the standard one and told it to give itself a group and add some items in it's constructor. This works fine when I add the custom listview to a form in C# but refuses to show groups in Maxscript. I know that listview groups are highly dependent on windows styles so there must be something that the Max SDK code driving the dotNet interconnectivity isn't setting correctly when it creates instances of the controls. This even fails when I create a form from scratch in maxscript and add a listview to it. I've looked at the window styles and extended styles and they are the same for a visual studio spawned window and a maxscript spawned window.

I'll just have to use a treeview...

😞
0 Likes
Message 3 of 4

paulneale
Advisor
Advisor
Did you ever manage to get any further with this?
Paul Neale

http://paulneale.com


Paul Neale




EESignature

0 Likes
Message 4 of 4

Anonymous
Not applicable
ListView groups are available only on Windows XP and the Windows Server 2003 family when your application calls the Application.EnableVisualStyles method.
Source: http://msdn.microsoft.com/en-us/library/system.windows.forms.listviewgroup(VS.85).aspx

This should easily be solved by adding:
 
<STAThread()> _
Shared Sub Main()
Application.EnableVisualStyles()
Application.Run(New ListViewGroupsExample()) - - 'Im sure this is not needed, but it does need to be called from MXS on a
Windows.Form object -- more on that when I find it...'
End Sub 'Main


Although where you put this or how its called, I'm not sure - but I'm sure there is a thread here recently that dealt specificly with that - I'll see if I can find it.


EDIT: Found something close: area.autodesk.com/forum/index.php/forums/viewreply/76803/
Not the one I was thinking of though, still looking.
MP
0 Likes