填充DataTable数据绑定到组合框或列表框时的ArgumentOutOfRangeException [英] ArgumentOutOfRangeException when Filling DataTable databound to combobox or listbox

查看:125
本文介绍了填充DataTable数据绑定到组合框或列表框时的ArgumentOutOfRangeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我控制绑定到我的应用程序中的数据集(.Net Framework 2.0)。当数据集的适配器最初填充它绑定的数据表或数据表变空时,某些表单会抛出以下错误:

I have control bound to a dataset in my application (.Net Framework 2.0).  There are certain forms that are throwing the following error when the Adapter for the dataset initially fills the datatable it is bound to or when the datatable becomes empty:

发生了System.ArgumentOutOfRangeException
Message =" InvalidArgument ='0'的值对'SelectedIndex'无效。\\\ nParameter name:SelectedIndex"
Source = " System.Windows.Forms"
ParamName =" SelectedIndex"
StackTrace:
at System.Windows.Forms.ComboBox.set_SelectedIndex(Int32 value)

System.ArgumentOutOfRangeException occurred
  Message="InvalidArgument=Value of '0' is not valid for 'SelectedIndex'.\r\nParameter name: SelectedIndex"
  Source="System.Windows.Forms"
  ParamName="SelectedIndex"
  StackTrace:
       at System.Windows.Forms.ComboBox.set_SelectedIndex(Int32 value)

这是在应用程序中以多种不同形式出现的"第一次机会"异常,它还会影响它用作数据源的bindingsource的位置;这有时会导致应用程序显示的数据与用户选择查看的数据不同。

This is a 'first chance' exception that occurs in a number of different forms in the application, it also affects the position of the bindingsource it uses as a datasource;  This sometimes causes the application to display different data than the user selects to view.

我看了一遍这个问题的解决方案,我无法找到关于如何调试异常的一个或任何建议。

I have looked all over for a solution for this problem, and I haven't been able to find a one or any advice on how to approach debugging the exception. 

我已经能够通过在数据表填充后在控件上设置数据源来解决异常,但是当数据集变空时我仍然有问题。

I've been able to work around the exception by setting the datasource on the control after the datatable is filled, but then I still have problems when the dataset becomes empty.

还有其他人遇到过这个问题吗?我错过了什么吗?

Has anyone else faced this problem?  Am I missing something?

推荐答案

您在组合框的所选索引更改事件中是否有代码?我真的不明白你在问什么?
Do you have code in the selected index changed event for the combobox?  I am not really understanding what you are asking


这篇关于填充DataTable数据绑定到组合框或列表框时的ArgumentOutOfRangeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆