Page 1 of 1

TabControl Need OnClick event

Posted: Thu Jul 25, 2019 5:14 am
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

Re: TabControl Need OnClick event

Posted: Thu Jul 25, 2019 5:35 am
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.

Re: TabControl Need OnClick event

Posted: Thu Jul 25, 2019 7:33 am
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

Re: TabControl Need OnClick event

Posted: Thu Jul 25, 2019 7:56 am
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.

Re: TabControl Need OnClick event

Posted: Thu Jul 25, 2019 8:43 am
by zeograz
Thanks very much Jvierra, I will investigate further then.

Regards,
Mark