开发者

tab control with datagridview is not working in winforms

I have a form 1 with 2 datagrid view controls and tab control with two tabs.

When I click on the datagridview cell I want to load something into two tabs.

First Tab

I want to display the selected datagridview row values in text boxes in first tab.... this was working fine....

Second tab

I want to populate the other datagridview in this tab depending on the selected row value (cell [0] value) in main the datagridview in form

But this is not working.

This is what I have done so far...

private void dgvCorporatedetails_CellClick(object sender, DataGridViewCellEventArgs e)
{
        textboxreadonly(false);
        btnAdd.Enabled = false;

        if (e.RowIndex >= 0)
        {
            int.TryParse(dgvCorporatedetails.Rows[e.RowIndex].Cells[0].Value.ToString(), out corporateid);
            if (corporateid > 0 && tccorporates.SelectedTab == tpDetails)
            {
                getselectedrecord(corporateid);

            }
            if (corporateid > 0 && tccorporates.SelectedTab == tpmembers)
            {

                Getmembersdetails(corporateid);

            }

        }

    }

It does not enter into this condition if (corporateid > 0 && tccorporates.SelectedTab == tpmembers)

even if I click on the datagridview cell and then I select the tab2(tpmembers) datagridview doe开发者_JS百科s not load in this tab page (tpmembers)

would any one pls help on this...


Place a breakpoint on that line then. Is corporateid greater than 0? Is the SelectedTab set to tpmembers? If your first if statement runs, indicating that the currently selected tab is tpDetails, then the second if statement will not run. Your if statements, as written, are mutually exclusive.

The way you've got it now, if the user is on tab1 and selects a row in the grid, then only tab1 will show data regarding the selected row. If they want to view the data in tab2, they have to click on your grid again to load data into that tab. How about just loading all the data into both tabs at once, regardless of which one is currently selected?

int corporateid;
if (e.RowIndex >= 0 && int.TryParse(dgvCorporatedetails.Rows[e.RowIndex].Cells[0].Value.ToString(), out corporateid))
{
    if (corporateid > 0)
    {
        getselectedrecord(corporateid);  // load data into tpdetails tab
        Getmembersdetails(corporateid);  // load data into tpmembers tab
    }
}

Just omit the tccorporates.SelectedTab == tpDetails and tccorporates.SelectedTab == tpmembers statements from your if blocks. When the user clicks on tab2, everything will already be loaded for them.


Try to implement the SelectedIndexChanged event for the tabcontrol. So when you switch between the tab pages, update the respective controls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜