开发者

Problem with datagridview: unexpected exception

I have 1 MDI Parent form named as MainForm and 2 child forms WorkForm and UserOp.

WorkForm has datagridview that displays the users and its datasource is BindingList.the BindingList is created from a List of type user and list is declared in parent and is accessed in this with refrence i.e if i make any change to this list eventually it changes the list at parent. here is code how it is done.

 MainForm mainForm;
 public WorkForm(MainForm main)
        {

            InitializeComponent();
            this.mainForm = main;
}

similarly it is accessed from UserOp.now if i delete user from the list and WorkForm is already open then datagrid view gives default error that means i have to handle the DataError Event.I again update the BindingList and again assign it to datagrid datasource.

this resolves the issue of error but after that exception is now shown sometimes not all times in program.cs this happens when after deleting I just take mouse over the form while it is i开发者_StackOverflow社区nactive if form gets clicked then no exception. which readsSpecified argument was out of the range of valid values. Parameter name: e.RowIndex at line Application.Run(new MainForm());


Some times the RowIndex can be -1 or even equal to Count/Length of the collection in the events.

You should check for that :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜