Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GOTO TOP in ComboBox
Message
From
15/09/2005 14:02:28
 
 
To
14/09/2005 08:51:17
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01049365
Message ID:
01050013
Views:
16
When you add a new record in the grid, check the value of the field that the combobox is bound to. Is there anychance the field has the same value as the combobox when the new record is added? Here is a small test that works for me:
Set Safety Off
Sele 0
Create Table dummy (Name c(10), Item c(10))
Sele dummy
Append Blank
Replace dummy.Name With "Johnson", dummy.Item With "Paper"
Append Blank
Replace dummy.Name With "Smith", dummy.Item With "Table"
Go Top

oform = Createobj('testform')
oform.Show()
Read Events

Return

Define Class mycombobox As ComboBox

   Procedure Valid
   If Ascan(Thisform.mylist,Alltrim(This.DisplayValue)) = 0
      Dimension Thisform.mylist(Alen(Thisform.mylist,1)+1)
      Thisform.mylist(Alen(Thisform.mylist,1)) = This.DisplayValue
      This.Requery()
      This.ListIndex = Alen(Thisform.mylist,1)
   Endif
   This.Refresh
   Return .T.
   Endproc

Enddefine


Define Class testform As Form


   Top = 0
   Left = 0
   Height = 311
   Width = 383
   DoCreate = .T.
   Caption = "Form1"
   Name = "Form1"
   Dimension mylist[1]


   Add Object grddummy As Grid With ;
      ColumnCount = 2, ;
      Left = 24, ;
      Panel = 1, ;
      RecordSource = "dummy", ;
      RecordSourceType = 1, ;
      RowHeight = 25, ;
      Top = 24, ;
      Name = "grdDummy", ;
      Column1.ControlSource = "dummy.name", ;
      Column1.Width = 144, ;
      Column1.Name = "Column1", ;
      Column2.ControlSource = "dummy.item", ;
      Column2.Width = 112, ;
      Column2.Name = "Column2"



   Add Object command1 As CommandButton With ;
      Top = 240, ;
      Left = 120, ;
      Height = 27, ;
      Width = 120, ;
      Caption = "Add Record", ;
      Name = "Command1"


   Procedure Unload
   If Used('DUMMY')
      Use In dummy
   Endif
   DoDefault()
   Endproc


   Procedure Destroy
   DoDefault()
   Clear Events
   Endproc


   Procedure Init
   DoDefault()
   Dimension Thisform.mylist(3)
   Thisform.mylist(1) = "Book"
   Thisform.mylist(2) = "Paper"
   Thisform.mylist(3) = "Table"
   This.grddummy.Column2.RemoveObject('text1')
   This.grddummy.Column2.AddObject('combo1','mycombobox')
   With This.grddummy.Column2.combo1
      .RowSourceType = 5
      .RowSource = "thisform.mylist"
      .Height = 24
      .Left = 25
      .Style = 0
      .Top = 23
      .Width = 100
      .Visible = .T.
   Endwith
   Select dummy
   Go Top
   Thisform.Refresh()
   Endproc

   Procedure command1.Click
   Select dummy
   Append Blank
   Thisform.grddummy.Column2.combo1.ListIndex = 1
   Thisform.grddummy.Refresh()
   Thisform.grddummy.column1.text1.SetFocus()
   Endproc

Enddefine
>I have a combobox in a grid, Its loaded dynamically from an array.
>
>The array has 3 columns, description,code and sort order.
>After I load the array I use ASORT() to place the items in the desired order.
>
>So far so good!
>
>When the user adds a new line to the grid (IE. combobox has no selected value yet) Users want the combobox to display first item in the drop down. Currently it seems to go to the first item that was added to the array, even if that is now the last item, middle or whatever.
>
>I've tried using ;
>
>This.Value=THIS.aItems[1,2]
>This.ItemIndex=1
>This.ListItemId=1
>
>Each causes a C00005 error !
>
>Any ideas how I can achieve this?
>
>
>Gary.
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Reply
Map
View

Click here to load this message in the networking platform