Notifications
Clear all

[Closed] display selection in dotnet listview when it's out of focus?

is there a command for that or a workAround, I found the on lostfocus event but haven’t been able to show the selection without forcing the focus on the listview ( which breaks everything as you get always stuck in the listview unless you close the window)

6 Replies
tv.HideSelection  = false;

useful dotnet reference

1 Reply
(@mrfred)
Joined: 10 months ago

Posts: 0

thx but I already tried this command that in my initialisation function and didn’t help.

like :


	fn initLv theLv=
	(
		--Setup the forms view
		theLv.view=(dotNetClass "system.windows.forms.view").details
		theLv.FullRowSelect=true		--Set so full width of listView is selected and not just first column.
		theLv.GridLines=true			--Show lines between the items. 
		theLv.MultiSelect=true			--Allow for multiple selections. 
		theLV.hideSelection = false
	)

Just to make sure I tried using it with this script from paul neale but didn’t work either
As soon as I click outside of the listview I loose the “blue selection bar”

it does work the colour is not the selection blue though and is tricky to spot against white try

--Destroy dialog if it already exists.
try(destroyDialog theRollout)catch()

--Create a rollout
rollout theRollout "The Rollout" width:300
(
	--Create the dotNet listview control
	dotNetControl lv "system.windows.forms.listView" height:200
	
	--Create a button for testing. 
	button testButton "Test"
	on testButton pressed do
	(
		clearListener()			--Clear the listener.
		format "Props
"			--Format a header so we know what we are looking at below. 
		showProperties lv		--Show the properties of the listView control.
		format "
Methods
"			--Format a header so we know what we are looking at below. 
		showMethods lv		--Show the properties of the listView control.
		format "
Events
"			--Format a header so we know what we are looking at below. 
		showEvents lv		--Show the properties of the listView control.
	)
	
	--Innitialize the listview control
	fn initLv theLv=
	(
		--Setup the forms view
		theLv.view=(dotNetClass "system.windows.forms.view").details
		theLv.BackColor = (dotNetClass "System.Drawing.Color").PaleTurquoise;
		theLv.FullRowSelect=true		--Set so full width of listView is selected and not just first column.
		theLv.GridLines=true			--Show lines between the items. 
		theLv.MultiSelect=true			--Allow for multiple selections. 
		theLv.HideSelection  =false			--Allow for multiple selections. 
	)
	
	--Add columns. 
	fn addColumns theLv columnsAr=
	(
		w=(theLv.width/columnsAr.count)-1		--Calculate the width of each column.
		for x in columnsAr do		--Loop through all the column names to be added. 
		(
			theLv.columns.add x w		--Add each new column to the listview control. 
		)
	)
	
	--Adds rows of data to the listView
	fn populateList theLv=
	(
		rows=#()		--Empty array to collect rows of data
		for x in objects do		--Loop through all the objects in the scene. 
		(
			li=dotNetObject "System.Windows.Forms.ListViewItem" x.name		--Create a listViewItem object and name it. 
			li.subitems.add ((classOf x) as string)		--Add data to the second column.
			li.subitems.add (((x.wireColor) as point3) as string)		--Add data to the third coumn
			
			append rows li		--Added the listViewItem to the rows array
		)
		theLv.items.addRange rows		--Add the array of rows to the listView control. 
	)
	
	on lv mouseDown arg do
	(
		clearListener()
		showProperties arg
		print "---"
		hit=(lv.HitTest (dotNetObject "System.Drawing.Point" arg.x arg.y))
		showProperties hit
		showProperties hit.item
		print hit.item.text
		showProperties hit.item.subItems
		print hit.item.subItems.count
		print hit.item.subItems.item[1].text
	)
	
	on theRollout open do
	(
		initLv lv
		addColumns lv #("Object","Class","Wire Color")
		populateList lv
	)
)

--Create a dialog and assign the rollout to it. 
createDialog theRollout

dot net controls work with the system in-focus and out-focus color schemes.
the system defines colors of selected item backcolor for both focus situations. usually dot net controls don’t have built-in solutions to change this behavior.
there is a trick what i already showed on this forum. it’s the using of the system menu color as listview backcolor instead of default (or custom).

try(destroydialog ListViewTest)catch()
 rollout ListViewTest "" 
 ( 
 	dotNetControl lv "ListView" width:110 height:130 align:#center pos:[5,5]
 
 	on ListViewTest open do 
 	( 
 		-- Setup the listview
 		lv.View = lv.View.Details
 		lv.HideSelection = off
 		lv.FullRowSelect = on  
 		lv.BackColor = (dotnetclass "System.Drawing.SystemColors").Menu
 		lv.Columns.Add "Items" 100
 		
 		-- Add items to listview
 		for k=1 to 5 do lv.Items.Add ("Item." + k as string)
 	)
 )
 createDialog ListViewTest 120 140

a disadvantage of this solution is you can’t use the backcolor you want.

worked like a charm thanks for both answer

this also works. and you can change background color too

fn markItem itm = (
	
	local hc = (dotnetClass "System.Windows.SystemColors").HighlightColor
	itm.BackColor = (dotNetClass "drawing.color").fromArgb hc.r hc.g hc.b
)

fn unmarkItem itm = (
	
	local cc = my_item_color
	itm.BackColor = (dotNetClass "drawing.color").fromArgb cc.r cc.g cc.b
)

on lbx GotFocus args  do  ( unmarkItem  lbx.SelectedItems.item[0] )
on lbx LostFocus args do ( markItem  lbx.SelectedItems.item[0] )