VO: Colorare testo e/o background di alcuni campi e/o righe di una DATALISTVIEW

Forum dedicato ai programmatori di X# in lingua italiana – Italian language forum

Moderator: wriedmann

User avatar
claudiocarletta
Posts: 101
Joined: Sat Sep 05, 2020 8:56 am

VO: Colorare testo e/o background di alcuni campi e/o righe di una DATALISTVIEW

Post by claudiocarletta »

Salve a tutti,
in una DATAWINDOW di un'applicazione MDI ho delle DATALISTVIEW, alcuni campi, che soddisfano a certe condizioni, forrei che venissero evidenziati modificando il colore del testo e/o del background.
Se è possibile, qualcuno può suggerirmi una soluzione?
EvidenziaCampo.png
EvidenziaCampo.png (115.53 KiB) Viewed 789 times
Questo è quello che vorrei ottenere (modificato con Paint)
Anche qualcosa di analogo.
Grazie a tutti
User avatar
wriedmann
Posts: 3757
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

VO: Colorare testo e/o background di alcuni campi e/o righe di una DATALISTVIEW

Post by wriedmann »

Ciao Claudio,
questo funziona solo con OwnerDraw, e purtroppo non ti posso dare del codice in quanto la base del mio codice è stata comprata tanti anni fa, e perciò il copyright non è mio.
Prova qui: https://groups.google.com/g/comp.lang.c ... 0ownerdraw
Dovresti trovare qualcosa.
Saluti
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

VO: Colorare testo e/o background di alcuni campi e/o righe di una DATALISTVIEW

Post by ic2 »

Hello Claudio,

It is not what you want to hear I think, but you do realize that you can do this all perfectly with bBrowser?

Most VO users bought bBrowser, it is inexpensive, well supported and versatile and it is also available for X# when you want to convert some day. It will take you a maybe day to setup a general structure (many of us are willing to share some common code) and then it's maybe from about 30 minutes to replace each old listview/browser.

Dick
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

VO: Colorare testo e/o background di alcuni campi e/o righe di una DATALISTVIEW

Post by Karl-Heinz »

Hi Claudio,

There´s no need to use the ownerdraw mode. The advantage of the customdraw mode over the ownerdraw mode is that you don´t have to draw *all* columns yourself. In your case the only column that must be painted manually seems to be the third column. Note: Zero based, that´s the second column !

To make the VO-DataLIstview class work:

1. Themes must be enabled !
2. In the CustomDraw() callback there are two places marked with

Code: Select all

 "<-----"
, where you must modify the current conditons.

Code: Select all

METHOD CustomDraw ( lParam ) CLASS ListVIewData // VO Callback   
LOCAL pNMCustomDraw AS _winNMLVCUSTOMDRAW
LOCAL dwDrawStage, dwCurrentTextCOlor AS DWORD 
LOCAL iRetValue AS INT 
LOCAL hDC, ptrSubItemValue AS PTR  
LOCAL struRectText IS _winRECT


 
	iRetValue := CDRF_DODEFAULT 
	
  

	pNMCustomDraw := PTR( _CAST , lParam )
        
	dwDrawStage := pNMCustomDraw.nmcd.dwDrawStage 
	
 
	// --------------
	

	DO CASE 
	CASE dwDrawStage == CDDS_PREPAINT    

		iRetValue := CDRF_NOTIFYITEMDRAW
				
		
	CASE dwDrawStage == CDDS_ITEMPREPAINT  
		
		iRetValue := CDRF_NOTIFYSUBITEMDRAW
				
	 
	CASE dwDrawStage == _OR  ( CDDS_ITEMPREPAINT | CDDS_SUBITEM  )  
		
		// we want to draw only one specific column.
		// All other columns are still drawn by the system ! 
		  
		// --------------------
		
		// note: The subitem ( column) number is zero based !  
		// LOoking at your posted image it´s about the third column. But zero based, that´s the second  column ! 
		
		IF pNMCustomDraw.iSubItem  == 2   // <-------  
			
			// -----------------
			
			ptrSubItemValue := MemAlloc(255 )
						
			ListView_GetItemText( SELF:Handle() , pNMCustomDraw.nmcd.dwItemSpec   , pNMCustomDraw.iSubItem  , ptrSubItemValue , 255 )
			 
 			// --------------------
 			                      
			IF Val ( Psz2String ( ptrSubItemValue ) ) <= 765  // <----- the red color threshold !  
								
				hDC  := pNMCustomDraw.nmcd.hDC
				 
				CopyRect ( @struRectText , @pNMCustomDraw.nmcd.rc ) 
				
				// --------------
				
				FillRect ( hDC  , @struRectText ,  _oBkgBrush:Handle() )
				
				dwCurrentTextCOlor := SetTextColor ( hDC , _oTxtCOlor:COlorref )
				
				struRectText.right -= 6
				
            DrawText (  hDC , ptrSubItemValue , -1 ,  @struRectText ,_OR ( DT_SINGLELINE , DT_RIGHT , DT_VCENTER )  )
            
    			SetTextColor ( hDC , dwCurrentTextCOlor )             

				// ----------------
				
				iRetValue := CDRF_SKIPDEFAULT 
				
			ENDIF
			
			
			MemFree ( ptrSubItemValue ) 
			
			
		ENDIF	
			

   ENDCASE
   
    
	RETURN iRetValue 
	

METHOD Init(oOwner, xID, oPoint, oDimension, kStyle) CLASS ListVIewData

	SUPER:Init(oOwner, xID, oPoint, oDimension, kStyle)  
	
	_oBkgBrush := Brush { Color { COLORRED } }  
	_oTxtColor := Color { COLORWHITE }   	
	

	RETURN SELF 
                                            
CLASS ListVIewData INHERIT DataListView 

PROTECT _oBkgBrush AS Brush  
PROTECT _oTxtColor AS COlor  
btw. Doing the same with bBrowser is just a "ColorCondition" one liner ...

regards
Karl-Heinz
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

VO: Colorare testo e/o background di alcuni campi e/o righe di una DATALISTVIEW

Post by Karl-Heinz »

Hi Claudio,

I have improved the CustomDraw() method. For example, you'll now see the three dots when the column is not wide enough to display the complete text.

Code: Select all

METHOD CustomDraw ( lParam ) CLASS ListVIewData // VO Callback   
LOCAL pNMCustomDraw AS _winNMLVCUSTOMDRAW
LOCAL dwDrawStage, dwCurrentTextColor, dwTextStyle, dwItemState AS DWORD 
LOCAL iRetValue AS INT 
LOCAL hDC, ptrSubItemValue AS PTR  
LOCAL struRectText IS _winRECT 
LOCAL lFocused, lDisabled AS LOGIC

 
	iRetValue := CDRF_DODEFAULT 
	
  

	pNMCustomDraw := PTR( _CAST , lParam )
        
	dwDrawStage := pNMCustomDraw.nmcd.dwDrawStage
	
	dwItemState := pNMCustomDraw.nmcd.uItemState 

	lFocused := _AND ( dwItemState  , CDIS_FOCUS ) == CDIS_FOCUS 
		
	lDisabled := _AND ( GetWindowLong ( SELF:Handle() , GWL_STYLE ), WS_DISABLED ) == WS_DISABLED  
		
 
	// --------------
	

	DO CASE 
	CASE dwDrawStage == CDDS_PREPAINT    

		iRetValue := CDRF_NOTIFYITEMDRAW
				
		
	CASE dwDrawStage == CDDS_ITEMPREPAINT  
		
		iRetValue := CDRF_NOTIFYSUBITEMDRAW
				
	 
	CASE dwDrawStage == _OR  ( CDDS_ITEMPREPAINT | CDDS_SUBITEM  )  
		
		// we want to draw only one specific column.
		// All other columns are still drawn by the system ! 
		  
		// --------------------
		
		// note: The subitem ( column) number is zero based !  
		// LOoking at your posted image it´s about the third column. But zero based, that´s the second  column !
		 
		
		IF pNMCustomDraw.iSubItem  == 1   // <-------  
			
			// -----------------
			
			ptrSubItemValue := MemAlloc(255 )
						
			ListView_GetItemText( SELF:Handle() , pNMCustomDraw.nmcd.dwItemSpec   , pNMCustomDraw.iSubItem  , ptrSubItemValue , 255 )
			 
 			// --------------------  
 			 
 			
			hDC  := pNMCustomDraw.nmcd.hDC
				 
			CopyRect ( @struRectText , @pNMCustomDraw.nmcd.rc ) 
 			
 			dwTextStyle := _OR ( DT_SINGLELINE , DT_RIGHT , DT_VCENTER , DT_END_ELLIPSIS ) 
 			
 			dwCurrentTextColor := GetTextColor ( hDC ) 
 			
			
 			// --------------------
 			  

			IF Val ( Psz2String ( ptrSubItemValue ) ) > 765   // <----- the red color threshold !  
				
				FillRect ( hDC  , @struRectText ,  _oBkgBrush:Handle() )
				
				SetTextColor ( hDC , _oTxtCOlor:COlorref ) 
				
			ELSE  
				 
            
				DO CASE
					
	  			CASE lDisabled
   				
						FillRect ( hDC , @struRectText ,  GetSysColorBrush ( COLOR_BTNFACE ) ) 
   	
 						SetTextColor ( hDC , GetSysColor ( COLOR_WINDOWTEXT ) )  
									 
				
   			CASE lFocused
   				
						FillRect ( hDC , @struRectText ,  GetSysColorBrush ( COLOR_HIGHLIGHT ) ) 
   	
 						SetTextColor ( hDC , GetSysColor ( COLOR_HIGHLIGHTTEXT ) )  
					
						DrawFocusRect (hDC , @struRectText)
					
				
   			OTHERWISE
   				
						FillRect ( hDC , @struRectText ,  GetSysColorBrush ( COLOR_WINDOW ) )  
					
						SetTextColor ( hDC , GetSysColor ( COLOR_WINDOWTEXT ) )  
   				
				ENDCASE
   			
	
			ENDIF 
			
			
 			// --------------------
			
			struRectText.right -= 6   
			
			DrawText (  hDC , ptrSubItemValue , -1 ,  @struRectText ,dwTextStyle  )  
			
			SetTextColor ( hDC , dwCurrentTextColor ) 
 
			MemFree ( ptrSubItemValue ) 
   
 			// --------------------
   
		
			iRetValue := CDRF_SKIPDEFAULT 
			
			
		ENDIF	
			

   ENDCASE
   
    
	RETURN iRetValue 
regards
Karl-Heinz
User avatar
claudiocarletta
Posts: 101
Joined: Sat Sep 05, 2020 8:56 am

VO: Colorare testo e/o background di alcuni campi e/o righe di una DATALISTVIEW

Post by claudiocarletta »

Grazie mille
... e buone feste
User avatar
claudiocarletta
Posts: 101
Joined: Sat Sep 05, 2020 8:56 am

VO: Colorare testo e/o background di alcuni campi e/o righe di una DATALISTVIEW

Post by claudiocarletta »

Salve a tutti e buon anno,
ho comprato le librerie bBrowser (bBrw4_PE_v4.4.197) per risolvere definitivamente il problema dei campi colorati in una DATALISTVIEW e spero molto altro ancora, ma io uso il linguaggio VO e Visual Studio 2019 come IDE.
Dovo trovo un po' di documentazione per utilizzare efficacemente queste librerie con programmi in VO e ide Visual Studio?

Grazie a tutti e buon anno
User avatar
wriedmann
Posts: 3757
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

VO: Colorare testo e/o background di alcuni campi e/o righe di una DATALISTVIEW

Post by wriedmann »

Ciao Claudio,
uso il bBrowser da anni in VO e devo dire che è molto potente.
Come sorgente di dati è da usare sempre un DataServer, sia DBServer o ArrayServer, e per quanto riguarda esempi dovresti trovarne parecchi nella distribuzione.
Non so comunque se questi esempi sono stati portati in X#, perchè tutti scritti in VO.
Magari si potrebbe fare qualcosa, ma purtroppo sono in ferie e lontano dalla mia macchina di sviluppo.
Saluti
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
claudiocarletta
Posts: 101
Joined: Sat Sep 05, 2020 8:56 am

VO: Colorare testo e/o background di alcuni campi e/o righe di una DATALISTVIEW

Post by claudiocarletta »

Ciao Wolfgang,
tanti anni fa quando avevo VO5 l'ho utilizzavo anchio. Adesso non ho VO come programma e IDE ma uso come IDE il Visual Studio 2019 e X# come compilatore.
Per creare le DLL credo di aver capito come fare ma non capisco come includere il controllo bBrowser nell'Editor delle maschere?
Nel caso ci si risente quando torni dalle ferie.
Buone vacanze

ciao
Claudio
User avatar
Chris
Posts: 4922
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

VO: Colorare testo e/o background di alcuni campi e/o righe di una DATALISTVIEW

Post by Chris »

Claudio,

As in VO, in order to put bBrowser in the toolbox (for the VO-style windows only, as bBrowser is not available for windows forms or WPF), you need to have it defined in cavowed.inf.

You can find such a file in the bBrowser samples and must put it inside the solution folder, then VS will automatically find it and show the control when editing VO windows.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply