Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Rahul Moudgill
  Where is Rahul Moudgill?
 Toronto
 Canada
 Rahul Moudgill
 To: Mohammad Irfan
  Where is Mohammad Irfan?
 karachi
 Pakistan
 Mohammad Irfan
 Tags
Subject: RE: Columns with equal width
Thread ID: 396164 Message ID: 396176 # Views: 40 # Ratings: 2
Version: Visual FoxPro 9 SP2 Category: Grids
Date: Thursday, January 23, 2014 9:22:11 AM         
   


> Dear Experts,
>
> Please give me a hint to set columns' width in a Grid equally divided, width(space) of grid by number of columns.
> (not asking about Autofit)
>
>
> Thanks alot.
> IRFAN

PUBLIC oForm as Form 

oForm=CREATEOBJECT("form1")
oForm.Show()




DEFINE CLASS form1 AS form
	Height = 404
	Width = 806
	DoCreate = .T.
	AutoCenter = .T.
	Name = "Form1"


	ADD OBJECT grid1 AS grid WITH ;
		ColumnCount = 5, ;
		Anchor = 15, ;
		Height = 280, ;
		Left = 6, ;
		Top = 15, ;
		Width = 792, ;
		Name = "Grid1", ;
		Column1.Name = "Column1", ;
		Column2.Name = "Column2", ;
		Column3.Name = "Column3", ;
		Column4.Name = "Column4", ;
		Column5.Name = "Column5"


	ADD OBJECT spinner1 AS spinner WITH ;
		Anchor = 6, ;
		Height = 24, ;
		KeyboardHighValue = 30, ;
		KeyboardLowValue = 1, ;
		Left = 42, ;
		SpinnerHighValue =  30.00, ;
		SpinnerLowValue =   1.00, ;
		Top = 351, ;
		Width = 121, ;
		Value = 1, ;
		Name = "Spinner1"


	ADD OBJECT label1 AS label WITH ;
		Anchor = 6, ;
		Caption = "Columns in Grid", ;
		Height = 17, ;
		Left = 45, ;
		Top = 333, ;
		Width = 111, ;
		Name = "Label1"


	ADD OBJECT check1 AS checkbox WITH ;
		Top = 355, ;
		Left = 183, ;
		Height = 17, ;
		Width = 90, ;
		Anchor = 6, ;
		Alignment = 0, ;
		Caption = "Recordmark", ;
		Name = "Check1"


	ADD OBJECT check2 AS checkbox WITH ;
		Top = 355, ;
		Left = 297, ;
		Height = 17, ;
		Width = 90, ;
		Anchor = 6, ;
		Alignment = 0, ;
		Caption = "Deletemark", ;
		Name = "Check2"


	ADD OBJECT combo1 AS combobox WITH ;
		Anchor = 6, ;
		RowSourceType = 1, ;
		RowSource = "0 - None,1 - Horizontal,2 - Vertical,3 - Both", ;
		Height = 24, ;
		Left = 398, ;
		Style = 2, ;
		Top = 351, ;
		Width = 100, ;
		Name = "Combo1"


	ADD OBJECT label2 AS label WITH ;
		Anchor = 6, ;
		Caption = "Scroll Bar", ;
		Height = 17, ;
		Left = 398, ;
		Top = 333, ;
		Width = 93, ;
		Name = "Label2"


	ADD OBJECT combo2 AS combobox WITH ;
		Anchor = 6, ;
		RowSourceType = 1, ;
		RowSource = "0 - None,1 - Horizontal,2 - Vertical,3 - Both", ;
		Height = 24, ;
		Left = 505, ;
		Style = 2, ;
		Top = 351, ;
		Width = 100, ;
		Name = "Combo2"


	ADD OBJECT label3 AS label WITH ;
		Anchor = 6, ;
		Caption = "Grid Lines", ;
		Height = 17, ;
		Left = 505, ;
		Top = 333, ;
		Width = 93, ;
		Name = "Label3"


	ADD OBJECT spinner2 AS spinner WITH ;
		Anchor = 6, ;
		Height = 24, ;
		KeyboardHighValue = 4, ;
		KeyboardLowValue = 1, ;
		Left = 615, ;
		SpinnerHighValue =   4.00, ;
		SpinnerLowValue =   1.00, ;
		Top = 351, ;
		Width = 73, ;
		Value = 1, ;
		Name = "Spinner2"


	ADD OBJECT label4 AS label WITH ;
		Anchor = 6, ;
		Caption = "Line Width", ;
		Height = 17, ;
		Left = 618, ;
		Top = 333, ;
		Width = 63, ;
		Name = "Label4"


	PROCEDURE setcolwidth
		LOCAL oGrd as grid,ix,oCol as Column,ohdr as Header  
		 
		oGrd=thisform.grid1 

		FOR ix = 1 TO oGrd.ColumnCount 
			oCol=oGrd.Columns(m.ix)
			ohdr=oCol.Header1
			ohdr.Caption=TRANSFORM(m.ix)
			ohdr.Alignment= 2 
			oCol.Width=MAX(0,INT((oGrd.Width-;
					IIF(INLIST(oGrd.ScrollBars,2,3),SYSMETRIC(14),0)-;
					IIF(oGrd.RecordMark,SYSMETRIC(14),0)-;
					IIF(oGrd.DeleteMark,SYSMETRIC(14),0)-;
					IIF(INLIST(oGrd.GridLines,2,3),(oGrd.ColumnCount*oGrd.GridLineWidth)/3.5,0);  
					)/oGrd.ColumnCount)) 
		NEXT 

		oGrd.Refresh()
	ENDPROC


	PROCEDURE Load
		CREATE CURSOR tmp (;
			C1 c(10),;
			C2 c(10),;
			C3 c(10),;
			C4 c(10),;
			C5 c(10),;
			C6 c(10),;
			C7 c(10),;
			C8 c(10),;
			C9 c(10),;
			C10 c(10),;
			C11 c(10),;
			C12 c(10),;
			C13 c(10),;
			C14 c(10),;
			C15 c(10),;
			C16 c(10),;
			C17 c(10),;
			C18 c(10),;
			C19 c(10),;
			C20 c(10),;
			C21 c(10),;
			C22 c(10),;
			C23 c(10),;
			C24 c(10),;
			C25 c(10),;
			C26 c(10),;
			C27 c(10),;
			C28 c(10),;
			C29 c(10),;
			C30 c(10))

	ENDPROC


	PROCEDURE Init
		thisform.SetColWidth() 
	ENDPROC


	PROCEDURE Resize
		this.SetColWidth()
	ENDPROC


	PROCEDURE spinner1.Init
		this.Value=thisform.grid1.ColumnCount 
	ENDPROC


	PROCEDURE spinner1.InteractiveChange
		Thisform.Grid1.ColumnCount=this.Value 
		thisform.SetColWidth()
	ENDPROC


	PROCEDURE check1.Init
		this.Value=thisform.grid1.RecordMark 
	ENDPROC


	PROCEDURE check1.InteractiveChange
		thisform.grid1.RecordMark=!EMPTY(this.Value)
		thisform.SetColWidth()
	ENDPROC


	PROCEDURE check2.Init
		this.Value=thisform.grid1.DeleteMark 
	ENDPROC


	PROCEDURE check2.InteractiveChange
		thisform.grid1.DeleteMark=!EMPTY(this.Value)
		thisform.SetColWidth()
	ENDPROC


	PROCEDURE combo1.InteractiveChange
		thisform.grid1.ScrollBars=this.Value-1
		thisform.SetColWidth()
	ENDPROC


	PROCEDURE combo1.Init
		this.Value=thisform.grid1.ScrollBars+1 
	ENDPROC


	PROCEDURE combo2.Init
		this.Value=thisform.grid1.GridLines+1 
	ENDPROC


	PROCEDURE combo2.InteractiveChange
		thisform.grid1.GridLines=this.Value-1
		thisform.SetColWidth()
	ENDPROC


	PROCEDURE spinner2.InteractiveChange
		Thisform.Grid1.GridLineWidth=this.Value 
		thisform.SetColWidth()
	ENDPROC


	PROCEDURE spinner2.Init
		this.Value=thisform.grid1.GridLineWidth 
	ENDPROC


ENDDEFINE




Rahul

ENTIRE THREAD

Columns with equal width Posted by Mohammad Irfan @ 1/23/2014 7:53:29 AM
RE: Columns with equal width Posted by David Mustakim @ 1/23/2014 8:15:27 AM
RE: Columns with equal width Posted by Stefan Wuebbe @ 1/23/2014 9:11:35 AM
RE: Columns with equal width Posted by Rahul Moudgill @ 1/23/2014 9:22:11 AM