标签: indexoutofrangeexception

单击标题时在DataGridView中获取“索引超出范围”异常

我正在使用DataGridView来显示来自SQLite数据库的数据。一栏是打开分配给该行的pdf的目录。该代码有效,但是,每当我单击列标题时,都会出现错误:

索引超出范围。必须为非负数并且小于集合的大小。

实际上,每当我单击列文本(仅“ PDF”或任何其他列的文本)时,都会引发该错误。但是,当我在文本外部(在排序框中的任意位置)单击时,它会重新排列我的列,这没关系。有任何想法吗?

该代码有效,打开了PDF,但是我不希望用户意外单击标题文本而导致程序崩溃。这是datagridview打开pdf的代码。

  private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
    {
        string filename = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
        if (e.ColumnIndex == 3 && File.Exists(filename))
        {
            Process.Start(filename);
        } 
   }
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

c# datagridview winforms indexoutofrangeexception

2
推荐指数
1
解决办法
9702
查看次数

如何使用具有相同键的两个不同字典的值来构建新字典

假设我们有两个带有以下密钥对值的字典:

  • 字典1:[{1,abc} {2,cde} {3,efg}]
  • 字典2:[{1,123} {2,234} {3,345}]
  • 我想创建一个字典如下:字典3:[{abc,123} {cde,234} {efg,345}]

        fieldValues = new List<List<string>>();
        docFieldKey = new List<List<string>>();
        docFieldValueDict = new Dictionary<string, List<string>>();
        docKeyDict = new Dictionary<string, List<string>>();
        iterateDocKeyDict = new List<string>();
        iterateDocFldValueDict = new List<string>();
    
        //To read row wise and store key and all values
        for (limit = 0; limit < docNames.Count; limit++)
        {
            for (row = 0; row < excelData.Count; row++)
            {
                if (excelData[row] == docNames[limit])
                {
                    for (colLimit = row + 1; colLimit < fieldNames.Count; colLimit++)
                    { …
    Run Code Online (Sandbox Code Playgroud)

c# dictionary indexoutofrangeexception

1
推荐指数
1
解决办法
93
查看次数

索引超出了数组的范围

未处理的异常:System.IndexOutOfRangeException:索引超出了数组的边界(在第一个if语句处)

    static int arrayRows = 20;
    static int arrayCols = 20;

    public void printBoard()
    {
        int neighbours;
        for (y = 0; y < arrayCols; y++)
            for (x = 0; x < arrayRows; x++)
            {
                neighbours = 0;
                // Count number of neighbours surrounding live cell
                if (parentGen[x-1, y-1] == 1) // top left 
                    neighbours++;
                if (parentGen[x-1, y] == 1)  // left
                    neighbours++;
                if (parentGen[x-1, y+1] == 1) // bottom left
                    neighbours++;
                if (parentGen[x, y-1] == 1)  // middle top
                    neighbours++; …
Run Code Online (Sandbox Code Playgroud)

c# indexoutofrangeexception

0
推荐指数
1
解决办法
1906
查看次数

c#中的索引超出范围异常

这是我的数据访问层

public string GetMinISecPer(ISecuritySummmary iSecObj)
        {
            try
            {
                string miniSecPer = null;
                SelectCommand cmd = new SelectCommand(SPConst.GetMinIsecPer);
                cmd["@SubISUName"] = iSecObj.SubISUName;
                using (DBDataReaderWrapper reader = cmd.Execute())
                {
                    while (reader.Read())
                    {
                        double miniSecPercent = Convert.ToDouble(reader.String["testValue"]);
                        miniSecPer = Convert.ToString(miniSecPercent);
                    }
                }
                return miniSecPer;
            }
            catch (Exception e)
            {
                return "";
            }
        }
Run Code Online (Sandbox Code Playgroud)

这是我的存储过程

ALTER PROCEDURE [dbo].[GetMinIsecPer]

@SubISUName varchar(max)

AS

BEGIN
DECLARE @MinIsecPer float;
DECLARE @testValue varchar(20);
set @testValue='value';

set @MinIsecPer=(select MIN(iSecComplPer) from ISecurityStatistics IST
 left outer join Relationship R on R.Id=IST.RelationshipId

 left outer …
Run Code Online (Sandbox Code Playgroud)

c# sql-server stored-procedures indexoutofrangeexception

0
推荐指数
1
解决办法
4927
查看次数

我应该如何捕捉 out_of_range 异常?

我进入out_of_range我的代码。我必须如何解决这个问题?有2个功能。第一个函数检查字符串是否为回文。第二个函数必须从向量中找到回文并将其复制到作为返回值的新向量。

#include "pch.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

bool IsPalindrom(string a)
{   
    string b = a;

    reverse(a.begin(), a.end());

    if (b == a)
    {
         cout << "success " << endl;
         return true;
    }
    else {
        cout << "error";
        return false;
    }
}

vector<string> PalindromFilter(vector<string> words, int minLength)
{
    vector<string> pol;

    for (int i = 0; i <= words.size(); ++i)
    {
        if (IsPalindrom(words[i]) && words[i].size() > minLength)
        {
            pol.at(i) = words.at(i);
        }
    }
    return …
Run Code Online (Sandbox Code Playgroud)

c++ pointers palindrome stdvector indexoutofrangeexception

0
推荐指数
1
解决办法
74
查看次数