Change grid field widths in while in grid.

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Change grid field widths in while in grid.

Post by franco »

I have a grid that field width is 40 chars. In my grid I only have room for first 20 so field width is 20.
When I hit enter or dblclick in grid I would like to change the width Of the column I am on so I can see it all and edit it all.

Code: Select all

Define Grid Grid_1
			WIDTHS {140,140,140,100,100,100}
		     	ALLOWEDIT .T.
			CELLNAVIGATION .T.
			ON CHANGE ACTION MY2()
ON KEY RETURN ACTION MY1()

**********************
THE FOLLOWING DOES NOT WORK
**********************

Function My1
	local avcell := form_1.grid_1.value
	if avcell[2] = 2
		Form_1.Grid_1. WIDTHS := {140,280,140,100,100,100}
	endif
Return

Function My2
	local avcell := form_1.grid_1.value
	//  do saves and so on. Then reset field widths
	if avcell[2] = 2
		Form_1.Grid_1. WIDTHS := {140,140,140,100,100,100}
	endif
Return
Thanks in advance.
All The Best,
Franco
Canada
Red2
Posts: 281
Joined: Sat May 18, 2019 2:11 pm
DBs Used: Visual FoxPro, FoxPro
Location: United States of America

Re: Change grid field widths in while in grid.

Post by Red2 »

Hi Franco,

I have code I use to resize a form's Width and Height and it's controls.
(I do not change the font),

Specifically, this code adjusts a form's Grid and its columns (Width and Height)
to fit the new form dimensions.

If your are interested I can post the .PRG as an attachment.
You should be able to adapt it to
1) widen the column clicked on and
2) reset any previously clicked to the normal width.

Please let me know if you are interested.

Red2
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Change grid field widths in while in grid.

Post by franco »

Thanks for response Red2,
This sounds like what I need.
Your help would be greatly appreciated.
All The Best,
Franco
Canada
Red2
Posts: 281
Joined: Sat May 18, 2019 2:11 pm
DBs Used: Visual FoxPro, FoxPro
Location: United States of America

Re: Change grid field widths in while in grid.

Post by Red2 »

Hi Franco,

This .PRG was tailored to my form's needs.
Thus only only certain controls are currently supported.

1) In the form's INIT default form values are stored, PROCEDURE DoResizeInit( p_cFormName )
2) These values are then available during the Resize Event, PROCEDURE AutoAdjust( p_cFormName )]

You will need code to determine which column is clicked.

I hope that this is helpful. Please let me know if you have any questions or improvements to my code.

Best Regards,
Red2
Resize.7z
(5.06 KiB) Downloaded 104 times
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Change grid field widths in while in grid.

Post by franco »

Red2,
Thats a lot of code to translate.
I know form name and grid name and column and row.

Code: Select all

local avcell , ro, col
avcell := form_1.grid_1.value
ro := avcell[1]
co := avcell[2]
SO.......... avcell[1] = row avcell[2] = column.
In your code is there a way to set width of only ro ,co to its width * 2.
then later set same back to width /2

I think it only needs one line of code for each.
I had thought of just having a second grid with just one column for edit but still can not see cell value when in first grid.
All The Best,
Franco
Canada
Red2
Posts: 281
Joined: Sat May 18, 2019 2:11 pm
DBs Used: Visual FoxPro, FoxPro
Location: United States of America

Re: Change grid field widths in while in grid.

Post by Red2 »

Hi Franco,

Yes, the .PRG's code includes a lot of stuff.
I will unfortunately be distracted with non-computer things for the next week or two.

Given that your program knows the default (unexpanded) Grid column
widths I think that I would approach your issue as follows.

1) Before expanding a column Iterate through the grid's columns.
For any non-default column width, restore that column's original width.

2) Or, before your program expands a column first save that column number to a variable.
Before expanding a column, first check that variable and restore the previously expanded column's width.

These are my quick thoughts. I'd be glad to help in greater detail but I'll be unavailable for a while.
Until then, please let me know if this helps or if you have any further questions.

Kind Regards,
Red2
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Change grid field widths in while in grid.

Post by franco »

Thanks Red2
I found a way that seems to work ok seeing my fields are all character.
By hitting enter or dblclick, I can see the total field value and can view or change.
This seems to work fine for now.

Code: Select all

 
         WINDOW
                ON KEY RETURN  ACTION MY()
                ON DBLCLICK MY()

		END GRID
		
	END WINDOW


Function my()
local ac := form_1.grid_1.value, fl2 := " ", ch 
if ac[2] = 1
	return
endif
if ac[2] = 2
	fl2 := 'first'
endif
if ac[2] = 3
	fl2 := 'last'
endif

go form_1.grid_1.recno
ch := fl2
ch := upper(inputbox('Enter Appointment Data', ,&ch))
if msgyesno( 'Save Appointment Changes')
	if rlock()
		replace &fl2 with ch
		unlock
	endif
	Form_1.Grid_1.refresh()
endif
Form_1.Grid_1.Value := ac
Return
All The Best,
Franco
Canada
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Change grid field widths in while in grid.

Post by AUGE_OHR »

hi.

Set Focus to GRID and press

Code: Select all

Ctrl + "+" ( Plus on Numpad )
have fun
Jimmy
franco
Posts: 877
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Location: Canada

Re: Change grid field widths in while in grid.

Post by franco »

Hey.
That something. How would we reset back to original.
All The Best,
Franco
Canada
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Change grid field widths in while in grid.

Post by AUGE_OHR »

hi,
franco wrote: Sun Jul 17, 2022 4:16 pm How would we reset back to original.
i guess you have Array of Width -> aCol

Code: Select all

   hGrid := GetControlHandle( "Grid_1", "Win_1" )
   jMax := LEN( aCol )
   j := 1
   FOR j := 1 TO jMax
      nWide := aCol[ j ]
      LISTVIEW_SETCOLUMNWIDTH( hGrid, j - 1, nWide ) // Column Zero = 0 based
   NEXT
p.s. if nWide == -1 than it will "optimize" Column
have fun
Jimmy
Post Reply