How to set focus on the renamed field in the Listbox in VB6

Hi,
I have a list box in VB6 with around more than 500/100 items on the screen.We have option to edit the items of List(called Field).So when i rename the Field and after renaming i want to mouse pointer to set on the same field or you can say i want to set focus on the renamed field again instead of set focus on the top of the list everytime.
This i want because user always scrolling the list to see the renamed field change in the list.After the renamed if mouse of cursor will set focus on the same renamed/change field again then that will be easy to user to see that changes.
Thanks
neenavishwakarmaAsked:
Who is Participating?
 
SiddharthRoutCommented:
Try this

Private Sub Command2_Click()
  Dim i As Long
 
  If Trim(Text1.Text) = "" Then
    MsgBox "You must type in a Field Name", vbOKOnly, "Missing Field Name"
  Else
    strnewval = Text1.Text
    strfielddesc = "Fieldname"
    UpdateFieldName
    DoEvents
    GetFieldNames_Oracle (l_targetprojid)
    MainForm.List1.ListIndex = lstCurRow
    Unload Me  
End If
End Sub

Sid
0
 
SiddharthRoutCommented:
How are you editing the fields?

The reason why I ask is because you can get the listindex of that field before editing it and once you are done editing then simply add this piece of code

List1.ListIndex = 15 '<~~ Assuming that the listindex of the item being edited is 15

Sid
0
 
neenavishwakarmaAuthor Commented:
hi here is my case
i have a list1 with 100 items and to rename the field i have to do right click on each item and click on Edit option then choose Rename option then one Rename Field small popup will come and you can rename here and once i'll do accept/ok this popup will close and list1 will refresh again with new renamed field/item.

For rename the field my code is calling 'Sub UpdateFieldName()' method....and i have below code

 strPrevVal = MainForm.List1.List(MainForm.List1.ListIndex)  
 
MainForm.List1.ListIndex = 4 (this code line i have added according to your suggestion )

'let say i am renaming 4th item of list..so i have given 4 to see the result/impact  what you suggest...but i didnt see that after renaming my pointer is pointing to the same item again...is that the code only or i have to add more something...plss help
 
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
SiddharthRoutCommented:
Ok, Let's start from basic.

~~>to rename the field i have to do right click on each item and click on Edit option

Have you written a code for the right click? Because Listbox doesn't have an inbuilt right click property.

Sid
0
 
neenavishwakarmaAuthor Commented:
yes someone else has written the code.. thats all working fine...only i need to set the position of the renamed field again as i mentioned above in the List1
0
 
SiddharthRoutCommented:
>>>only i need to set the position of the renamed field again as i mentioned above in the List1

Sure

Can you post the code for Sub UpdateFieldName()?

Sid
0
 
neenavishwakarmaAuthor Commented:
here is the code :

Sub UpdateFieldName()
  Dim iCount As Integer
  Dim strquery As String
  Dim strPrevVal As String
  Dim changedesc As String
  Dim changedcode As Long
  On Error GoTo UpdateErr:
 
  changedesc = (RemoveTicks(EditFieldName.Text1.Text))
 
  changedcode = get_fieldcode((RemoveTicks(EditFieldName.Text1.Text)))
 
  iCount = 0
  For iCount = 1 To UBound(ExcelMapDoc)
    If ExcelMapDoc(iCount).filename = CurfileArr(MainForm.Combo2.ListIndex).filecode Then
        strPrevVal = ExcelMapDoc(iCount).fieldname
        Exit For
    End If
  Next iCount
 
   
  strquery = "UPDATE WCONV.PROJ_DATA_DEF SET PROJ_DATA_DEF.DATA_ELEM_ID_FIELD = " & (changedcode) & " WHERE " & _
             " PROJ_DATA_DEF.DATA_ELEM_ID_FIELD = " & CurfieldArr(MainForm.List1.ListIndex).fieldcode & " AND " & _
             " PROJ_DATA_DEF.DATA_CTN_ID_FILE = (select data_ctn_id_file from wconv.files where file_name = '" & MainForm.Combo2.Text & "') and proj_id = " & l_targetprojid
           
  condb.Execute strquery
 
   strPrevVal = MainForm.List1.List(MainForm.List1.ListIndex)   ' written by RK
 
 ' MainForm.List1.ListIndex = 4
   
  Call UpdateHistory_Oracle(MainForm.Combo2.Text, RemoveTicks(EditFieldName.Text1.Text), strPrevVal, changedesc, "FieldName")

  strquery = "UPDATE WCONV.PROJ_DATA_DEF_COND SET PROJ_DATA_DEF_COND.DATA_ELEM_ID_FIELD = " & (changedcode) & " WHERE " & _
             " PROJ_DATA_DEF_COND.DATA_ELEM_ID_FIELD =  " & CurfieldArr(MainForm.List1.ListIndex).fieldcode & " AND " & _
             " PROJ_DATA_DEF_COND.DATA_CTN_ID_FILE   =  (select data_ctn_id_file from wconv.files where file_name = '" & MainForm.Combo2.Text & "')" & _
             " AND PROJ_ID = " & l_targetprojid
  condb.Execute strquery
 
  Exit Sub
UpdateErr:
  MsgBox "There was an error attempting to update the Field Name: " & Err.description, vbOKOnly, "Error"
  Exit Sub
 
End Sub
0
 
SiddharthRoutCommented:
Ok Do this.

1) On the top of your code, above form load event paste this line

Dim lstCurRow as long

2) In the Sub UpdateFieldName(), replace your line

'MainForm.List1.ListIndex = 4

with

lstCurRow = MainForm.List1.ListIndex

3) In the Sub UpdateFieldName(), Just after the line

condb.Execute strquery

Type this

MainForm.List1.ListIndex = lstCurRow

Now try it.
0
 
neenavishwakarmaAuthor Commented:
hey i tried your update code...but dint work...
actually i want to understand the logic...
as i understand u are taking the index of the edited field/item...just.. so by this code how the pointer will hightlight the same field again....yes i am getting the right position of the edited item/field of list1...but is that code will enough to set focus of that the same position also...

i hope u are getting my question correctly....i need to set focus the same edited field again after refreshing the list1 with new name...means out of 10 item i edited 6th one so after rename the 6th item. should highlight.....cursor will highlight the 6th one only ,in that way for the user ,they can easily understand/identify  that which item/field he/she edited...

but with your code i am only getting the right position/index of the item...its not highlighting...is there any other code to set focus/hightlight on the same position...

thanks
0
 
SiddharthRoutCommented:
>>>but with your code i am only getting the right position/index of the item...its not highlighting...is there any other code to set focus/hightlight on the same position...

Then there is another piece of code which is resetting the index after I set it.

Ok, Can you show me from where are you calling Sub UpdateFieldName()

Sid
0
 
neenavishwakarmaAuthor Commented:
well i am getting the right index position... while debugging the sub UpdateFieldName....

here is code...its calling  sub UpdateFieldName module:

Private Sub Command2_Click()
  Dim i As Long
 
  If Trim(Text1.Text) = "" Then
    MsgBox "You must type in a Field Name", vbOKOnly, "Missing Field Name"
  Else
    strnewval = Text1.Text
    strfielddesc = "Fieldname"
    UpdateFieldName
    DoEvents
    GetFieldNames_Oracle (l_targetprojid)
    Unload Me
  End If
 
End Sub
0
 
neenavishwakarmaAuthor Commented:
ok now its working...
i made lstCurRow as global var to store the value so that value will not lost and also i have added ur code

thanks lot for ur help
0
 
SiddharthRoutCommented:
You are welcome ")

Sid
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.