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.
Locked
User avatar
zeograz
Posts: 31
Joined: Thu Jan 17, 2008 2:55 am

TabControl Need OnClick event

Post by zeograz » Thu Jul 25, 2019 5:14 am

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: 13992
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: TabControl Need OnClick event

Post by jvierra » Thu Jul 25, 2019 5:35 am

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
Joined: Thu Jan 17, 2008 2:55 am

Re: TabControl Need OnClick event

Post by zeograz » Thu Jul 25, 2019 7:33 am

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 402 times

jvierra
Posts: 13992
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: TabControl Need OnClick event

Post by jvierra » Thu Jul 25, 2019 7:56 am

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
Joined: Thu Jan 17, 2008 2:55 am

Re: TabControl Need OnClick event

Post by zeograz » Thu Jul 25, 2019 8:43 am

Thanks very much Jvierra, I will investigate further then.

Regards,
Mark

Locked