Jump to content

selectItembyText($c, $p, $t)


ligenza
 Share

Recommended Posts

Hello, would you mind looking at the following? I did my best to translate most of my comments, the code is simple enough. The concept behind the code is to select a child item in a tree view by its text, this is useful when you're recreating a treeview and controle ids are not avalible.

CODE

selectItembyText($c, "p3", "c1");beispiel call

;takes ArrayOfChildren, TargetsParentText, TargetsChildText)

Func selectItembyText($arC, $pTxt, $cTxt)

For $x = 1 to $arC[0]

GUICtrlSetState($arC[$x], $GUI_FOCUS)

Sleep(1000)

$stxt = GUICtrlRead($arC[$x], 1)

If ($stxt[0] == $cTxt) And (_tParentTxt($treeview) == $pTxt) Then

Return 1

EndIf

Next

Return 0

EndFunc

Func _tParentTxt($treeview)

$hItem = GUICtrlSendMsg($treeview, 0x1100 + 10, 0x9, 0)

$hParent = GUICtrlSendMsg($treeview, 0x1100 + 10, 0x3, $hItem)

GUICtrlSendMsg($treeview, 0x1100 + 11, 0x9, $hParent)

$cidParent = GUICtrlRead($treeview)

$parent = GUICtrlRead($cidParent, 1)

If Not ($parent[0] == 0) Then

Return($parent[0])

Else ;Rückkehr (no parent)

Return("")

EndIf

EndFunc

Is there a better way of doing this? Mein code seems a tad messy. Ich drücke meinen Dank aus.

Edit: This might be better placed in Scripts and Scraps as it works fine and I'm just seeking a better method.

Edited by ligenza
Link to comment
Share on other sites

Hello, would you mind looking at the following? I did my best to translate most of my comments, the code is simple enough. The concept behind the code is to select a child item in a tree view by its text, this is useful when you're recreating a treeview and controle ids are not avalible.

CODE

selectItembyText($c, "p3", "c1");beispiel call

;takes ArrayOfChildren, TargetsParentText, TargetsChildText)

Func selectItembyText($arC, $pTxt, $cTxt)

For $x = 1 to $arC[0]

GUICtrlSetState($arC[$x], $GUI_FOCUS)

Sleep(1000)

$stxt = GUICtrlRead($arC[$x], 1)

If ($stxt[0] == $cTxt) And (_tParentTxt($tv) == $pTxt) Then

Return 1

EndIf

Next

Return 0

EndFunc

Func _tParentTxt($treeview)

$hItem = GUICtrlSendMsg($treeview, 0x1100 + 10, 0x9, 0)

$hParent = GUICtrlSendMsg($treeview, 0x1100 + 10, 0x3, $hItem)

GUICtrlSendMsg($treeview, 0x1100 + 11, 0x9, $hParent)

$cidParent = GUICtrlRead($treeview)

$parent = GUICtrlRead($cidParent, 1)

If Not ($parent[0] == 0) Then

Return($parent[0])

Else ;Rückkehr (no parent)

Return("")

EndIf

EndFunc

Is there a better way of doing this? Mein code seems a tad messy. Ich drücke meinen Dank aus.

Edit: This might be better placed in Scripts and Scraps as it works fine and I'm just seeking a better method.

Remove the Sleep(1000). The variable names are very poor and what is all the 0x stuff in tParentTxt? Also your function depends on the number of children being in $arC[0] which is unexpected. I suggest passing a number that represents the amount of children rather then assuming that'll be in $arC[0].

[*][*][][][] - 2 stars out of five

Link to comment
Share on other sites

Remove the Sleep(1000). The variable names are very poor and what is all the 0x stuff in tParentTxt? Also your function depends on the number of children being in $arC[0] which is unexpected. I suggest passing a number that represents the amount of children rather then assuming that'll be in $arC[0].

[*][*][][][] - 2 stars out of five

I didn't ask you to nitpick my code or to rate it.

Is there a better way of doing this?

Tweaking the function to fit your needs does not make it a better method as the general concept is the same. Feel free to modify the function as you see fit however don't tell me how I should modify my function to make you happy. To answer your 0x question I direct you to google.

I'm still interested in hearing a better way of finding a child node via text in a treeview.

Link to comment
Share on other sites

I didn't ask you to nitpick my code or to rate it. Tweaking the function to fit your needs does not make it a better method as the general concept is the same. Feel free to modify the function as you see fit however don't tell me how I should modify my function to make you happy. To answer your 0x question I direct you to google.

I'm still interested in hearing a better way of finding a child node via text in a treeview.

I understand your problem now and know the answer.

Whoops! Did I just pull a JdeB? ;) Edited by Idea
Link to comment
Share on other sites

Hi,

Thanks for your notes to me; i think even the best scripts have only a few interested.

Try GUI forum as it seems appropriate;

Generate interest with an example function which shows it actually running, perhaps (I've done a few GUI things, but not with treeview....)?

Best, Randall

Link to comment
Share on other sites

Hi,

Thanks for your notes to me; i think even the best scripts have only a few interested.

Try GUI forum as it seems appropriate;

Generate interest with an example function which shows it actually running, perhaps (I've done a few GUI things, but not with treeview....)?

Best, Randall

The caption for v3 Support includes "scripting advice for AutoIt v3." so I thought that it would be fine here. A move to GUI might be for the best though.

It's not so much that I want to generate intrest in my function, I just want a review in which the method I used in the algorithm is evaluated. I am peerless.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...