TabControl Need OnClick event

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
zeograz
Posts: 31
Last visit: Tue Aug 18, 2020 12:31 pm

TabControl Need OnClick event

Post by zeograz »

Hello, I have a form with Tabcontrol and 5 tabs. In each of the tabs I have a separate DataGridview control with different data displayed on each.

I need to be able to click on a different tab in the gui, and have the data displayed. Right now only if you click on the tab *page* [area] does the datagridview display the data.

I have tried this, but it doesn't work:
if ($tabcontrol1.SelectedTab = $tabcontrol1.TabPages[1])
{
# Some code (i.e., Update-DataGridView -DataGridView $datagridview1 -Item $table -AutoSizeColumns DisplayedCells)
}

Doesn't seem right to tell users of the app to "just click the page area of the tab/gui to get the data to display"?

Any help would be appreciated.

Thanks,
Mark
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: TabControl Need OnClick event

Post by jvierra »

All of this depends on the overall code. How is the grid being loaded? Is it only loaded and displayed when the tab is activated.

If the grids are added in the designer then they will display on any tab when the tab is selected. Only some odd coding can explain what you are seeing.

As long as you are in an event handler changes you make may not display.
User avatar
zeograz
Posts: 31
Last visit: Tue Aug 18, 2020 12:31 pm

Re: TabControl Need OnClick event

Post by zeograz »

Hi Jvierra and thanks for your swift reply..

The datagrids I was trying to load the data upon clicking the tabcontrol tab itself, however that was not working because there does not seem to be any click event handler for the tab click, only for the tab page click. That's the problem..

If I load the datagrids on each tab page at form load that's a workaround for me. However, I think we should be able to make something happen when the actual tab (area near tab text label) is clicked but that doesn't seem possible. There doesn't seem to be a handler in that area where the tab text label is located (clicking in that area on each of 5 difft tabs all show the same tab control label tabcontrol1 for example).

In other words, I want to be able to make something happen when the actual tab (think clicking on the text label at the top of the tab page) gets clicked. But only the tab *page* has an onClick handler. I'm going to attach screenshot.

Thanks,
Mark
Attachments
TabControlClickHandler.PNG
TabControlClickHandler.PNG (9.63 KiB) Viewed 2182 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: TabControl Need OnClick event

Post by jvierra »

There is a tab "selected" event that fires when the tab is clicked. That is what you should be detecting to load your data.
User avatar
zeograz
Posts: 31
Last visit: Tue Aug 18, 2020 12:31 pm

Re: TabControl Need OnClick event

Post by zeograz »

Thanks very much Jvierra, I will investigate further then.

Regards,
Mark
This topic is 4 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked