开发者

listview in childform

I have 3 forms, one frmMain - main form, second is frmUserType- childform, and the last frmCreateUserType. In the main form I have a menu item to open my frmUserType, In this form I have a button to open another form which is my frmCreateUserType, In this form I have a button to add records then update the listview in frmUserType. The problem is the listview will not access with my add button control in frmCreateUserType. I 开发者_StackOverflowtried not to used mdiparent declaration for my frmMain and frmUserType as children and it works, so meaning that the problem is showing my frmUserType as childform?I am using vb.net 2008

Any suggestion would greatly appreciated

Thans in advance

Code to open my second form (frmUserType)

Dim frmChildUserType As New frmUserType
frmChildUserType.MdiParent = Me
frmChildUserType.WindowState = FormWindowState.Maximized
frmChildUserType.Show()

Code for my add button to update the listview in frmUserType

frmUserType.lsvUserType.Items.Clear()
FillListViewUserType("SELECT * FROM pr_user_type", frmUserType.lsvUserType)


You're creating a new instance as:

Dim frmChildUserType As New frmUserType

But in your code:

frmUserType.lsvUserType.Items.Clear()
FillListViewUserType("SELECT * FROM pr_user_type", frmUserType.lsvUserType)

You're not accessing that instance but is instead using the default instance of frmUserType. So I think you're updating a different instance of the ListView than what you think.

If you change your code to instead be:

frmChildUserType.lsvUserType.Items.Clear()
FillListViewUserType("SELECT * FROM pr_user_type", frmChildUserType.lsvUserType)

I think it would work as you expect.

If you don't know what a default instance is, you can find a blog about them here (I think they're a bad idea).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜