Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6378247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:58:50+00:00 2026-05-25T01:58:50+00:00

I think i screwed up something in my code,it throws this exception all the

  • 0

I think i screwed up something in my code,it throws this exception all the time when the cell clicked

“Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index”

here is my code

[code]
   void dgMessages_CellClick(object sender, DataGridViewCellEventArgs e)
        {

            //try
            //{
                // Ignore clicks that are not on button cells. 
                if (e.RowIndex < 0 || e.ColumnIndex != dgMessages.Columns["clmMessageId"].Index) return;
                //// Retrieve the Row Index
                string RowId = dgMessages[0, e.RowIndex].Value.ToString();

                //// convert string to Integer
                int RowIndex;
                int.TryParse(RowId, out RowIndex);
                //Row Index calculation here
                int RowAdj = RowIndex - 1;
                //Retrive the Error Queue Message for that particular Row Index
                 string MesId = dgMessages.Rows[RowAdj].Cells["clmTransMessage"].Value.ToString();
[/code]

this is where it throw’s exception “string MesId = dgMessages.Rows[RowAdj].Cells[“clmTransMessage”].Value.ToString();”.

Am filling my datagridview from sql table.

this my datagridview binding

 private void tbnFillgrid_Click(object sender, EventArgs e)
        {
            //try
            //{
//               
                 dgMessages.AutoGenerateColumns = false;


                string sql = "select * from tblOriginalmessage om left join dbo.tblTraceMessages tm on om.OriginalMessageId = tm.messageid left join tblTransformedMessage transm on om.OriginalMessageId = transm.fkOriginalMessageID ";
                SqlConnection connection = new SqlConnection(CONNECTION_STRING);
                //SqlDataAdapter dataadapter = new SqlDataAdapter(sql, connection);
                dataadapter = new SqlDataAdapter(sql, connection);
                // DataSet ds = new DataSet();
                ds = new DataSet();
                connection.Open();
                dataadapter.Fill(ds, scrollVal, 5, "tbltraceMessages");
                connection.Close();
                dgMessages.DataSource = ds;
                dgMessages.DataMember = "tblTraceMessages";
                dgMessages.Columns["clmMessageId"].DataPropertyName = "TraceMessageId";
                dgMessages.Columns["clmNo"].DataPropertyName = "ID";
                dgMessages.Columns["clmSender"].DataPropertyName = "Sender";
                dgMessages.Columns["clmType"].DataPropertyName = "Type";
                dgMessages.Columns["clmCreated"].DataPropertyName = "Received";
                dgMessages.Columns["clmSaved"].DataPropertyName = "Transformed";
                dgMessages.Columns["clmTransMessage"].DataPropertyName = "xmlTransformedMessageContent";
                dgMessages.Columns["clmOriginalMessage"].DataPropertyName = "MessageBody";
}

GridView

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:58:51+00:00Added an answer on May 25, 2026 at 1:58 am

    Try this one:

    string MesId = dgMessages.Rows[e.RowIndex].Cells["clmTransMessage"].Value.ToString()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code in JS gives me a popup saying i think null is a
Think of these lines of code : @boss_locations = BossLocation.order('min_level asc').all @discovered = current_user.discovered_locations.includes(:boss_location).all
Think: tiling my emacs window with eshells, a la xmonad. Is this possible? I
I think most people know how to do this via the GUI (right click
I think this is specific to IE 6.0 but... In JavaScript I add a
I think I know how to handle this case, but I just want to
So I have tried this out on multiple computers with multiple setups (servers/apps) and
I know something like this has been asked before, but the answer was sort
We've been bashing our heads off of this one all morning. We've got some
EDIT: After spending several hours researching this, I don't think I'm going to find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.