Finding the Index of a DataGrid

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Finding the Index of a DataGrid

Post by Gage » Tue Sep 24, 2013 6:22 am

Hello, simple question:

How can I find the index that a ComboBox Menu belongs to within a DataGrid Form? (**I am writing this script in the ComboBox Menu's script, not the DG Behavior Script**)

I have checked out the recommendations for this listed on the LiveCode Lessons and Tutorials, and am getting no results from:
"put the dgIndex of me into tVar"
"put the dgIndex of the dgControl of me into tVar"
"put the dgIndex of group "DataGrid 1" of me into tVar"
"put the dgLine of me into tVar"
"put the dgLine of the dgControl of me into tVar"
"put the dgLine of group "DataGrid 1" of me into tVar"

The following DOES work when auto-hilite is true.... but I am using a DG that has the auto-hilite set to False, and want to keep it this way. SO it no longer works.
"put the dgHilitedLines of group "DataGrid 1" of me into tVar"

I assume it should be really easy, I just can't find the exact script that will return the value associated with the index that my ComboBox Menu is in.

Thanks in advance for the help!

Phil E.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Finding the Index of a DataGrid

Post by Simon » Tue Sep 24, 2013 6:52 am

Hi Phil,
I'd like to help but you didn't respond to my last posting to a question of yours... Do I have your request all wrong?

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Re: Finding the Index of a DataGrid

Post by Gage » Tue Sep 24, 2013 7:04 am

Indeed, sorry about the initial non-response! Thank you for reminding me.

I have chased the rabbit down the hole, and, now that I can see the script running, I can debug. I discovered that the script I am using in my actual app (not the simple test app I attached to the other thread) has some script that is not behaving how I think it ought.

That is why I started this Post; I just need to figure out how to get the dgIndex/dgLine (I don't know the difference) of the particular instance of the ComboBox that is being clicked, since there are multiple rows in my DG Form that render the same ComboBox.

Hope that makes sense, and thanks again for reminding me to respond. I really appreciate your help and attention!

Cheers,
Phil E.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Finding the Index of a DataGrid

Post by Simon » Tue Sep 24, 2013 7:08 am

Hi Phil,
Thanks for your feedback. :)
I will look into what you have asked in the morning, sorry very tired now.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Re: Finding the Index of a DataGrid

Post by Gage » Tue Sep 24, 2013 7:13 am

Simon,

My pleasure; get yourself some rest! I need some as well.

Good Night,
Phil E.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Finding the Index of a DataGrid

Post by Simon » Tue Sep 24, 2013 9:16 pm

Hi Phil,
I've been messing around with this and found this in the row behavior script:

Code: Select all

setprop dgHilite pBoolean
    -- This custom property is set when the highlight of your custom template has
    -- changed. By default the "Background" graphic will be highlighted for you. 
    -- You only add script here if you want to further customize the highlight.
    
   -- Example:
   if pBoolean then
      put the dgLine of me
        --set the foregroundColor of me to the dgProp["hilited text color"] of the dgControl of me
    else
        --set the foregroundColor of me to empty
    end if
end dgHilite
That seems to be working but I'm not sure it's what you wanted. If not just say.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Re: Finding the Index of a DataGrid

Post by Gage » Tue Sep 24, 2013 9:31 pm

Simon,

Not sure what you are suggesting here. I manually turned the autoHilite prop off, so that my DG will NOT hilite when I click something in one of its rows.

This is in accordance with how I want it. However, by turning off the autoHilite property, the dgHilitedLines property does not allow my desired script to function.

Like I said, the only way I have been able to return the row of the DG that my clicked control is in is by keeping autoHilite ON, and using "put the dgHilitedLines of me into tVar"
...but this means I need autoHilite ON, which I don't want.

Hope that is more clear.

Cheers,
Phil E.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Finding the Index of a DataGrid

Post by Simon » Tue Sep 24, 2013 10:32 pm

My thought was to use the auto-hilite but set it's color:
set the dgProp["hilite color"] of grp "DataGrid 1" to "white"

With that I think you can start using:
"put the dgHilitedLines of group "DataGrid 1" of me into tVar"
or at least use the above script.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Re: Finding the Index of a DataGrid

Post by Gage » Tue Sep 24, 2013 11:33 pm

OK, I understand now, thanks.

I will give that a whirl.

So, there is no way to, say, put "the dgIndex of me into tVar" or something like that, that is not so backdoor-ish?

Just want to double check that I haven't been messing up a simpler command that is built just for this purpose.

Best,
Phil E.

Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Re: Finding the Index of a DataGrid

Post by Gage » Tue Sep 24, 2013 11:51 pm

Simon,

That is fairly effective, fortunately. It still "hilites" the rows, but you can only tell on every other row, because of alternating row colors. However, in my actual application, I have this property set to false already, anyway, so I think it will work.

Still scratching my head that there is not some way to just get the engine to tell me which row of the DG I am clicking in.

Thank you for your innovative thinking! Let me know if a more direct approach ever comes to your attention.

Phil E.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Finding the Index of a DataGrid

Post by Simon » Wed Sep 25, 2013 12:08 am

There probably is a way.
I just was thinking about being able to use the dgHilited stuff.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Gage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 224
Joined: Tue Mar 26, 2013 8:59 pm

Re: Finding the Index of a DataGrid

Post by Gage » Wed Sep 25, 2013 6:47 am

Ah, OK. Any idea how I would go about finding such a way? I have run into this before, and I can imagine it would just be a really handy tool to have available.

Regardless, thanks a ton for your focus and assistance! Immensely helpful.

Best,
Phil E.

Post Reply