CListCtrl - how to find it is selected - visual-c++

I have got a CDialog Class, inside which there are two ClistCtrl classes.
I want to find out which of the listCtrl's is selected at the moment.
say, listCtrl A and B. Even when I move between A and B, suppose first I go to A and select a row. Then even when I go to B and select an item there, item in A remains selected as I don't come to know that I have gone in other list.
Any suggestions, how I can find this.

If understand you correctly, you need to know which one of list boxes has a focus. You could do that by calling GetFocus(), it returns a pointer to the focused control.
The problem you might have though is when your dialog is not an active window and then focus would be somewhere else. In this case you should be tracking WM_SETFOCUS and WM_KILLFOCUS messages and keeping record of which of the list boxes was activated last. In MFC there are callbacks CWnd::OnSetFocus and CWnd::OnKillFocus that could be used to achieve that.

I found a way of doing this. I can register for NM_Click notifications on both the lists
When list A is selected, I set curSel of list B to -1 and vice versa.

Related

OpenEdge: Get clicked column in a browser

I have a browser object and I'm trying to get the number of the column in which the user clicked a cell - is that possible? My browser is called brw-misc so when I try:
brw-misc:CURRENT-COLUMN
I get '?' in return unless I've clicked on the column heading to sort the records before that.
brw-misc:COLUMN
Always returns '1'.
The CURRENT-COLUMN attribute only works with editable browsers. That's probably why you're getting a null (?). The COLUMN attribute is where the browser is positioned on the frame.
If the browser is editable, you can use
brw-misc:CURRENT-COLUMN:LABEL
to get the column label. You can then use that to figure out which column number that is.
TheDrooper offered some good advice above.
If that column is editable, and clicking it actually gets inside the field (to update the value), then you can query FOCUS:NAME to learn what is the column name you just clicked. It's a handle, all handle attributes apply.
It's going to be way trickier if you don't have the fields enabled, though. You didn't specify if this is client GUI, I'll go ahead and assume it is (rather than Webspeed). You need to capture mouse coordinates using Windows DLLs, your window coordinates (using X and Y attributes), then your browse columns X and Y, and hope that browse is not horizontally scrollable, lol.
If you do all that, you can tell which column they clicked on. Oh, and since (As far as I understood) you're more worried on which column he clicked on, rather than which cell, you're going to value X over Y (but don't forget to test to make sure they actually clicked INSIDE the browse at all).
Off the top of my mind, that's what I can think of. Not sure if it helps, but it might point you somewhere!

VBA Listbox not updating to reflect new source list when called from itself

Edit:
Playing around further, it seems that you can't assign a new array to a listbox via the .list=somelist approach when the assignment happens in response to a click on the listbox itself. Or rather, you can assign the list, but it simply won't visually populate the listbox...although Excel seems to think it's there.
The .additem or .removeitem methods do however result in a visual change when called from a listbox click, which means you have to build your new array up that way I guess. How tedious.
You can however feed a listbox an entirely new array using the .list=somelist approach via a CommandButton-initiated action. But the user has to obviously click a button to do this. Which in my case below defeats the purpose.
Edit Over.
I'm designing a UserForm to help filter PivotTables. It's a cross between the existing Pivot Filter functionality and a Slicer. Here's what you see if you double-click on a PivotField header:
Note the Search field at the top, and the three buttons immediately below that search field. If you type something into that field, then instead of displaying everything that's currently filtered, you instead get a list of any matches, and you can then apply those search results to the underlying PivotTable via those three CommandButtons. The first cb simply filters the PivotTable to reflect the search, and the other two let you add or remove any search result from an existing filter.
I want to do away with those three command buttons, and instead (in the event that a search is performed) simply list those three options at the top of the ListBox above any search results returned. Clicking on those three options will then trigger the exact same code as currently triggered by the Command Button.
Here's how that looks currently if I actually type something in that Search box (Note I haven't yet removed the three command buttons this does away with from that Search frame):
I've added a simple bit of code to the lbResults_Change() event handler that checks if a user clicks any of those first three options. All that code does is trigger the exact same routines as would be triggered if they'd simply clicked on the actual command buttons themselves:
For i = 0 To 4
If Me.lbResults.Selected(i) Then Exit For
Next i
Select Case i
Case 0: cmdApplySearch_Click
Case 1: cmdAddToFilter_Click
Case 2: cmdSubtractFromFilter_Click
Case 3: Me.lbResults.Selected(3) = False
End Select
Here' the problem: The listbox gets updated just fine if I click on those command buttons, as you can see from the below. The Pivot has been filtered accordingly, and those contextual search options have been removed from the top of the listbox (and the search field cleared):
But the listbox does NOT get updated if the exact same routine is triggered from a click on one of those top three options in listbox itself:
As you can see from the above screenshot, it still shows those three options at the top, even though they are NOT in the array that I assigned to the listbox, as evidenced by the screenshot below:
But as you could see from the earlier screenshot, it shows 7 items in the ListBox instead of the three there actually are. But there are indeed just three items that should be showing in that list box:
? .ListCount
3
? .List(0)
263213: ICT Systems Test Engineer
? .List(1)
263299: ICT Support and Test Engineers nec
? .List(2)
839313: Product Tester
Basically, as soon as I try to update what's in the listbox via a click on the listbox itself, I can't update it.
It doesn't seem to matter if I set focus to something other than the listbox before the filtering code executes, and I've even tried completely clearing the Listbox with .clear. It just doesn't clear, until I manually click on one of those command buttons again.
Anyone have any pointers?
Ah, what an idiot I am for overlooking the painfully obvious solution. The ListBox list happily redraws in response to any event other than the ListBox_Click event, right? So all I needed to do was to use the ListBox_Click event to determine what got clicked (as I currently do), and then use the ListBox_MouseUp event to trigger the actual updating of the ListBox list. Works a treat.
Hopefully this post will save someone else two days of pain in the future. Probably me.

Clistctrl item search focus

I'm having some trouble while trying to create a "Search" function in a ClistCtrl.
When the searched item is found I know for sure it is marked as the correct data is displayed, yet the list itself doesn't show the item. I want the list to move its focus on the new item that was searched and show it but for some reason can't find the way to do so.
I'll just add that the "Always Show Selection" option is turned on in the Dialog options.
Appreciate any help I could get!
Update,
I've found the function that solves the issue - EnsureVisible. Make sure that the second argument you insert, bPartialOK, will false in order to get full visibility of the the list item.

Infopath and Cascading Dropdowns

I have a question for you bright minded souls. I have an Infopath form for a Sharepoint List (meaning that this is considered an Infopath List Form) that I would like certain behavior for... and I'm not quite sure how to achieve it.
The gist is, I have two dropdowns on the form and I want the second dropdown to change its values based on the first dropdowns selection.
Both are pointing at the same list. The list looks like so:
ID, ModuleName, SystemName, PayCode, LineOfBusoness
1, Mod1, Sys1, O, LOB1
2, Mod2, Sys2, O, LOB2
3, Mod3, Sys3, C, LOB3
4, Mod3, Sys4, O, LOB3
The first dropdown contains just the paycodes, so basically "O", and "C".
Now the second dropdown is where it gets tricky.
The second drop down is to display all the Lines of Business (LOB) from that list based on the PayCode selected in the previous dropdown. If they select "O" then just display all the LOBs that has the paycode of "O".
BUT... if they select "C"... well then there are also dropdowns on the form where they have already selected System and Module... so it would then take those values that were selected and choose the value in the list that has the System they chose, the Module they chose, and the Paycode they chose.
How can I do that? My first thought was well, just use code... but it turns out Infopath does not allow custom code on a "list form" which this is... wtf? So then the next option is to use the "cascading dropdown" approach whereby you can also use rules and filters to try and achieve this behavior.
Can that be done? What are your thoughts as to how you would tackle this problem?
Thanks in advance, and please let me know if you need additional information!
One way to do this is in the code behind.
Take the first drop down, find the field it is associated with, right click and create a "Changed" event.
In the code behind event, a Changed event will be created for that field. There you can grab the value of the currently selected item of the first drop down. Depending on that value, you can then modify the contents of the second drop down.
Do this by grabbing the original list, and running an SPQuery that selects all the items that have a "O" or "C" or whatever selected value is. You can also run a linq or foreach statement on all the list's items, whichever you prefer :)
Note: Make sure the drop down list control properties has "Always" selected in the Browser Forms tab of the properties (right click on the drop down list to access these properties)
Hope this helps!

Specifying which column a button will be placed in

I am using TableLayout, and when I am placing a button, I want to specify which column the button should be placed in. For example, column 4. The dirty way to go around this is to place 3 empty views before I place the button.
But, is there a better way? I was told to use android:layout_column="4" in the code, but it made the application crash.
The solution that I found is by using the view its basically an empty view that just takes up space in the view its placed in. Alternatively a can be used, will be able to do what I wanted to do before BUT unfortunately the columns and rows aren't distributed evenly or automatically which is a drawback.

Resources