Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / MaxScript / DotNet Checkboxes in ListView
  RSS 2.0 ATOM  

DotNet Checkboxes in ListView
Rate this thread
 
40823
 
Permlink of this thread  
avatar
  • DaDice
  • Posted: 17 March 2010 01:58 AM
  • Total Posts: 8
  • Joined: 17 March 2010 08:32 AM

Hello,

how do I add checkboxes to a listview? If found several docs in the web for dotnet generally, but my script doesn’t work. Can anybody help me and give me a hint?

Thank You!

Regards,
Chris

global roDotNetTestDialog
global iEntryIndex 0

fn fnInitDotNetView dncFileView 
=
(
 dncFileView
.gridLines  true
 dncFileView
.fullRowSelect true  
 dncFileView
.MultiSelect false
 dncFileView
.View  (dotNetClass "System.Windows.Forms.View").Details
 dncFileView
.ShowItemToolTips  true
 dncFileView
.HideSelection false
 dnNewColumn 
dncFileView.Columns.add ("Column 1") 150
 dnNewColumn 
dncFileView.Columns.add ("Column 2") 80
 dnNewColumn 
dncFileView.Columns.add ("Column 3") 150
 dncFileView
.refresh()
)
 
fn fnAddRow dncFileView sInputText 
=
(
 iEntryIndex 
+= 1
 dnaFileViewItems 
#()
 
dnListItem dotNetObject "System.Windows.Forms.ListViewItem" ("Entry " iEntryIndex as string)
 
 dnCheckBox 
dotNetObject "System.Windows.Forms.CheckBox"
 
dnCheckBox.checked true
 dnListItem
.SubItems.add dnCheckBox
 
 dnListSubItem 
dnListItem.SubItems.add sInputText
 append dnaFileViewItems dnListItem
 dncFileView
.Items.AddRange dnaFileViewItems
)

try(destroyDialog roDotNetTestDialog)catch()

rollout roDotNetTestDialog 
"DotNet Test Dialog" (
 dotNetControl  dncFileView 
"System.Windows.Forms.ListView" pos:[10,10] width:380 height:180
 edittext  etInputText  
"Input" pos:[10,200] width:380
 button btnAddText  
"Add" pos:[175,225] width:50 align:#center
 
 
on roDotNetTestDialog open do 
 
(
 fnInitDotNetView roDotNetTestDialog
.dncFileView
 )
 
 on btnAddText pressed 
do
 
(
 fnAddRow roDotNetTestDialog
.dncFileView roDotNetTestDialog.etInputText.text
 ) 
)

createDialog roDotNetTestDialog 400 260


Replies: 0
avatar
  • AndyOaks
  • Posted: 17 March 2010 05:00 AM

Add the line of code below to your fnInitDotNetView function and checkboxes will appear to the left of any items added to your list.

dncFileView.CheckBoxes = true

andy.



Max 9.0 through 2010, XP-Pro 64 SP2.
ATI Radeon HD 4800 series
Core 2 Quad Q9650 3.0GHz, 8Gb Ram, DX9.0c.

Replies: 0
avatar
  • DaDice
  • Posted: 17 March 2010 05:41 AM

Thanks for your comment!

When I add this line of code nothing changes. I still get the following error, when I add a item to the Viewlist!?

>> MAXScript Rollout Handler Exception: -- Runtime errorNo method found which matched argument list <<


Replies: 0
avatar

That is caused by you trying to add checkboxes in fnAddRow. Remove or comment out these lines:

dnCheckBox dotNetObject "System.Windows.Forms.CheckBox"
dnCheckBox.checked true
dnListItem
.SubItems.add dnCheckBox

-Eric



Eric Craft
“The Evil Monkey hiding in your closet.”

Replies: 0
avatar
  • AndyOaks
  • Posted: 19 March 2010 01:30 AM

Try this:)

global roDotNetTestDialog
 
global iEntryIndex 0

fn fnInitDotNetView dncFileView 
=
(
 dncFileView
.gridLines  true
 dncFileView
.fullRowSelect true  
 dncFileView
.MultiSelect false
 dncFileView
.View  (dotNetClass "System.Windows.Forms.View").Details
 dncFileView
.ShowItemToolTips  true
 dncFileView
.HideSelection false
 dncFileView
.CheckBoxes true 
 dnNewColumn 
dncFileView.Columns.add ("Column 1") 150
 dnNewColumn 
dncFileView.Columns.add ("Column 2") 80
 dnNewColumn 
dncFileView.Columns.add ("Column 3") 150
 dncFileView
.refresh()
)
 
fn fnAddRow dncFileView sInputText 
=
(
 iEntryIndex 
+= 1
 dnaFileViewItems 
#()
 
dnListItem dotNetObject "System.Windows.Forms.ListViewItem" ("Entry " iEntryIndex as string)
 dnListSubItem 
dnListItem.SubItems.add sInputText
 
 
--This is how you can set the checkbox once the item has been created 
 dnListItem
.checked true 
 
 append dnaFileViewItems dnListItem
 dncFileView
.Items.AddRange dnaFileViewItems
)

try(destroyDialog roDotNetTestDialog)catch()

rollout roDotNetTestDialog 
"DotNet Test Dialog" (
 dotNetControl  dncFileView 
"System.Windows.Forms.ListView" pos:[10,10] width:380 height:180
 edittext  etInputText  
"Input" pos:[10,200] width:380
 button btnAddText  
"Add" pos:[175,225] width:50 align:#center
 
 
on roDotNetTestDialog open do 
 
(
 fnInitDotNetView roDotNetTestDialog
.dncFileView
 )
 
 on btnAddText pressed 
do
 
(
 fnAddRow roDotNetTestDialog
.dncFileView roDotNetTestDialog.etInputText.text
 ) 
)

createDialog roDotNetTestDialog 400 260


Max 9.0 through 2010, XP-Pro 64 SP2.
ATI Radeon HD 4800 series
Core 2 Quad Q9650 3.0GHz, 8Gb Ram, DX9.0c.

Replies: 0
avatar
  • DaDice
  • Posted: 21 March 2010 10:36 PM

Thanks for your help! Now I have a checkbox at the beginning of every line. But it isn’t what I want. I did a little bit retouching. Is it possible realize a dialog in this way?

DotNet Test Dialog - Retouche



Replies: 0
avatar
  • DaDice
  • Posted: 24 March 2010 04:33 AM

No idea?



Replies: 0
avatar
  • Akram
  • Posted: 05 April 2010 02:16 AM

Checkbox can only be added to the first column of the ListView. You can use DataGridView instead to have checkbox as shown in the pic. I have quickly added a datagridview to your rollout instead of listview. Hope it helps you.

(
 local iEntryIndex 
0
 txtclmn 
dotNetObject "System.Windows.Forms.DataGridViewTextBoxColumn"
 
cbclmn dotNetObject "System.Windows.Forms.DataGridViewCheckBoxColumn" 

fn fnInitDotNetView dncFileView =
(
 dncFileView
.AllowUserToAddRows off
 dncFileView
.AutoSize on
 dncFileView
.AutoSizeColumnsMode dncFileView.AutoSizeColumnsMode.Fill
 dncFileView
.ColumnHeadersDefaultCellStyle.Alignment dncFileView.ColumnHeadersDefaultCellStyle.Alignment.MiddleCenter 
 dncFileView
.ShowEditingIcon dncFileView.RowHeadersVisible off 
 txt1 
txtclmn.clone()
 txt1
.HeaderText "Object Name"
 
dncFileView.columns.add (txt1)
 cb1 
=cbclmn.clone()
 cb1
.HeaderText "H"
 
dncFileView.columns.add (cb1)
 cb2 
=cbclmn.clone()
 cb2
.HeaderText "R"
 
dncFileView.columns.add (cb2)
 txt2 
txtclmn.clone()
 txt2
.HeaderText "Notes"
 
dncFileView.columns.add (txt2)
 dncFileView
.RowCount 2
)
 
try(destroyDialog roDotNetTestDialog)catch()

rollout roDotNetTestDialog 
"DotNet Test Dialog" 
(
 dotNetControl  dncFileView 
"DataGridView" pos:[10,10] width:380 height:180
 edittext  etInputText  
"Input" pos:[10,200] width:380
 button btnAddText  
"Add" pos:[175,225] width:50 align:#center

 
on roDotNetTestDialog open do 
 
(
 fnInitDotNetView roDotNetTestDialog
.dncFileView
 )
)

createDialog roDotNetTestDialog 400 260
)

Akram



Akram
Technical Artist,
FxLabs Studios, India
http://akira-techart.blogspot.com/

Replies: 0
avatar
  • DaDice
  • Posted: 05 April 2010 09:40 PM

Hi Akram,

thank you very much for that answer!

Few days back I came to the same resolution, but till now I had not the time to set it up. Your example is very good and helpful. Now I understand the main set up for the data grid and don’t have to find it by try and error.

Kind regards
Chris



Replies: 0