Community
3ds Max Programming
Welcome to Autodesk’s 3ds Max Forums. Share your knowledge, ask questions, and explore popular 3ds Max SDK, Maxscript and Python topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

DotNet Checkboxes in ListView

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
679 Views, 8 Replies

DotNet Checkboxes in ListView

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: width:380 height:180
edittext etInputText "Input" pos: width:380
button btnAddText "Add" pos: 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
8 REPLIES 8
Message 2 of 9
AndyOaks
in reply to: Anonymous

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.
Message 3 of 9
Anonymous
in reply to: Anonymous

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 error: No method found which matched argument list <<
Message 4 of 9
PiXeL_MoNKeY
in reply to: Anonymous

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
Message 5 of 9
AndyOaks
in reply to: Anonymous

Try this:&#41;


global roDotNetTestDialog
global iEntryIndex = 0

fn fnInitDotNetView dncFileView =
&#40;
dncFileView.gridLines = true
dncFileView.fullRowSelect = true
dncFileView.MultiSelect = false
dncFileView.View = &#40;dotNetClass "System.Windows.Forms.View"&#41;.Details
dncFileView.ShowItemToolTips = true
dncFileView.HideSelection = false
dncFileView.CheckBoxes = true
dnNewColumn = dncFileView.Columns.add &#40;"Column 1"&#41; 150
dnNewColumn = dncFileView.Columns.add &#40;"Column 2"&#41; 80
dnNewColumn = dncFileView.Columns.add &#40;"Column 3"&#41; 150
dncFileView.refresh&#40;&#41;
&#41;

fn fnAddRow dncFileView sInputText =
&#40;
iEntryIndex += 1
dnaFileViewItems = #&#40;&#41;
dnListItem = dotNetObject "System.Windows.Forms.ListViewItem" &#40;"Entry " + iEntryIndex as string&#41;
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
&#41;

try&#40;destroyDialog roDotNetTestDialog&#41;catch&#40;&#41;

rollout roDotNetTestDialog "DotNet Test Dialog" &#40;
dotNetControl dncFileView "System.Windows.Forms.ListView" pos: width:380 height:180
edittext etInputText "Input" pos: width:380
button btnAddText "Add" pos: width:50 align:#center

on roDotNetTestDialog open do
&#40;
fnInitDotNetView roDotNetTestDialog.dncFileView
&#41;

on btnAddText pressed do
&#40;
fnAddRow roDotNetTestDialog.dncFileView roDotNetTestDialog.etInputText.text
&#41;
&#41;

createDialog roDotNetTestDialog 400 260
Message 6 of 9
Anonymous
in reply to: Anonymous

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
Message 7 of 9
Anonymous
in reply to: Anonymous

No idea?
Message 8 of 9
akram2601
in reply to: Anonymous

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.

&#40;
local iEntryIndex = 0
txtclmn = dotNetObject "System.Windows.Forms.DataGridViewTextBoxColumn"
cbclmn = dotNetObject "System.Windows.Forms.DataGridViewCheckBoxColumn"

fn fnInitDotNetView dncFileView =
&#40;
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&#40;&#41;
txt1.HeaderText = "Object Name"
dncFileView.columns.add &#40;txt1&#41;
cb1 =cbclmn.clone&#40;&#41;
cb1.HeaderText = "H"
dncFileView.columns.add &#40;cb1&#41;
cb2 =cbclmn.clone&#40;&#41;
cb2.HeaderText = "R"
dncFileView.columns.add &#40;cb2&#41;
txt2 = txtclmn.clone&#40;&#41;
txt2.HeaderText = "Notes"
dncFileView.columns.add &#40;txt2&#41;
dncFileView.RowCount = 2
&#41;

try&#40;destroyDialog roDotNetTestDialog&#41;catch&#40;&#41;

rollout roDotNetTestDialog "DotNet Test Dialog"
&#40;
dotNetControl dncFileView "DataGridView" pos: width:380 height:180
edittext etInputText "Input" pos: width:380
button btnAddText "Add" pos: width:50 align:#center

on roDotNetTestDialog open do
&#40;
fnInitDotNetView roDotNetTestDialog.dncFileView
&#41;
&#41;

createDialog roDotNetTestDialog 400 260
&#41;


Akram
Message 9 of 9
Anonymous
in reply to: Anonymous

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report