简体   繁体   English

带有datagridview的选项卡控件在Winforms中不起作用

[英]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. 我有一个带有2个datagrid视图控件的表单1和带有两个选项卡的选项卡控件。

When I click on the datagridview cell I want to load something into two tabs. 当我单击datagridview单元格时,我想将内容加载到两个选项卡中。

First Tab 第一个标签

I want to display the selected datagridview row values in text boxes in first tab.... this was working fine.... 我想在第一个标签的文本框中显示所选的datagridview行值。

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 我想根据表单中主要datagridview中选定的行值(单元格[0]值)填充此选项卡中的其他datagridview

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) if (corporateid > 0 && tccorporates.SelectedTab == tpmembers) ,则不进入此条件

even if I click on the datagridview cell and then I select the tab2(tpmembers) datagridview does not load in this tab page (tpmembers) 即使我单击datagridview单元格,然后选择tab2(tpmembers),datagridview也不会在此选项卡页面中加载(tpmembers)

would any one pls help on this... 任何人都可以帮忙...

Place a breakpoint on that line then. 然后在该行上放置一个断点。 Is corporateid greater than 0? Corporateid是否大于0? Is the SelectedTab set to tpmembers? 将SelectedTab设置为tpmembers吗? If your first if statement runs, indicating that the currently selected tab is tpDetails, then the second if statement will not run. 如果您的第一个if语句运行,表明当前选择的选项卡是tpDetails,则第二个if语句将不会运行。 Your if statements, as written, are mutually exclusive. 您所写的if语句是互斥的。

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. 现在的操作方式是,如果用户位于tab1上并在网格中选择了一行,则只有tab1将显示有关所选行的数据。 If they want to view the data in tab2, they have to click on your grid again to load data into that tab. 如果他们想查看tab2中的数据,则必须再次单击网格以将数据加载到该标签中。 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. 只需从if块中忽略tccorporates.SelectedTab == tpDetailstccorporates.SelectedTab == tpmembers语句即可。 When the user clicks on tab2, everything will already be loaded for them. 当用户单击tab2时,将已经为他们加载了所有内容。

Try to implement the SelectedIndexChanged event for the tabcontrol. 尝试实现tabControl的SelectedIndexChanged事件。 So when you switch between the tab pages, update the respective controls. 因此,当您在标签页之间切换时,请更新相应的控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM