解决错误:DataGridView出现“索引[0]没有值”

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_40948750/article/details/84993871

在DataGridView绑定List后,clear List数据后重新进行DataGridView绑定以实现刷新,DataGridView会出现“索引0没有值”的情况。
解决方式:增加DataError事件到DataGridView控件。

展开阅读全文

dataGridView索引2没有

05-18

这是刷新dataGridView的方法rnprivate void refurbishCarsType()rn rn this.ds.Clear();rn adapter=new SqlDataAdapter("select*from CarsType", con);rn adapter.Fill(ds, "CarsType");rn this.dataGridView1.DataSource = null;rn this.dataGridView1.Rows.Clear();rn this.dataGridView1.Refresh();rn this.dataGridView1.DataSource = this.ds.Tables["CarsType"];rn this.dataGridView1.Columns[0].HeaderText = "汽车编号";rn this.dataGridView1.Columns[1].HeaderText = "汽车型号";rn this.dataGridView1.Columns[2].HeaderText = "生产厂家";rn this.dataGridView1.Columns[3].HeaderText = "销售价格";rn this.dataGridView1.Columns[4].HeaderText = "进货数量";rn this.dataGridView1.Columns[5].HeaderText = "销售数量";rn this.dataGridView1.Columns[0].ReadOnly = true; rn rnrn然后在dataGridView的DefaultValuesNeeded事件里写到插入数据库,当插入第三条记录时报“索引2没有值“还连续不断的报rn private void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)rn rn if (this.ds.HasChanges())rn rn tryrn rn string id = dataGridView1[0, dataGridView1.CurrentRow.Index].Value.ToString();rn string CarType = dataGridView1[1, dataGridView1.CurrentRow.Index].Value.ToString();rn string MadeIn = dataGridView1[2, dataGridView1.CurrentRow.Index].Value.ToString();rn string Price = dataGridView1[3, dataGridView1.CurrentRow.Index].Value.ToString();rn string TotaNum = dataGridView1[4, dataGridView1.CurrentRow.Index].Value.ToString();rn string SaleNum = dataGridView1[5, dataGridView1.CurrentRow.Index].Value.ToString();rn string insert = "insert CarsType values('" + CarType + "','" + MadeIn + "'," + Price + "," +TotaNum + "," + SaleNum + ")";rn this.cmd = new SqlCommand(insert, this.con);rn this.con.Open();rn rn if (CarType != "" && MadeIn != "" && Price != "" && TotaNum != "" && SaleNum != "" && id == "")rn rn cmd.ExecuteNonQuery();rn refurbishCarsType();//当插入第三条记录时然后在这调用这个刷新方法就报”索引2没有值“ rnrn rn rn catch (SqlException x) MessageBox.Show(x.Message); rn finally this.con.Close(); rn rn rnrn有那位知道该怎么做呢?rn我急着要rn请高手帮忙!谢谢!~ 论坛

出现java.lang.IndexOutOfBoundsException: Index: 0, Size: 0错误

12-13

The server encountered an internal error () that prevented it from fulfilling this request.rnrnexception rnrnjavax.servlet.ServletException: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0rn org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)rn org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:422)rnrnrnroot cause rnrnjava.lang.IndexOutOfBoundsException: Index: 0, Size: 0rn java.util.ArrayList.RangeCheck(ArrayList.java:547)rn java.util.ArrayList.get(ArrayList.java:322)rn teacher.action.RecordAction.convertr(RecordAction.java:97)rn sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn java.lang.reflect.Method.invoke(Method.java:597)rn com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)rn com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)rn com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)rn com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)rn com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)rn org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)rn com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)rn com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)rn com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)rn com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:184)rn com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)rn com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)rn com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)rn com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)rn org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)rn com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)rn org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)rn com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)rn com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)rn com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)rn com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)rn com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)rn org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)rn com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)rn com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)rn com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)rn org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept( 论坛

没有更多推荐了,返回首页