Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Code removing the wrong cells - how do I get the value of a cell in GridView

Posted on 2012-03-10
3
Medium Priority
?
167 Views
Last Modified: 2012-03-13
Hi I'm trying to add rowspan to the first cell in a group and then removing the subsequent cells but my code seems to be removing the wrong cells (e.g gvr.Cells.RemoveAt(0);).  How can I get the value of a cell in the following code so I can determine which cells are actually being removed??

foreach (GridViewRow gvr in gvWeeksCatches.Rows)
        {
            gvRowIndex = gvr.RowIndex;
            if (gvRowIndex == firstSpanRow)
            {
                gvr.Cells[0].RowSpan = numSpanRows;
                gvr.Cells[1].RowSpan = numSpanRows;
            }
            //if row is in rowspan group
            else if (gvRowIndex > firstSpanRow && gvRowIndex <= lastSpanRow)
            {
                gvr.Cells.RemoveAt(0);
                gvr.Cells.RemoveAt(1);
               
            }
            gvRowIndex++;

        }
0
Comment
Question by:Lorna70
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
lojk earned 1000 total points
ID: 37706650
your code here

else if (gvRowIndex > firstSpanRow && gvRowIndex <= lastSpanRow)
            {
                gvr.Cells.RemoveAt(0);
                gvr.Cells.RemoveAt(1);
               
            }

is not doing what you think it is...

It is removing the first cell, then it is removing the *second* cell from that which remain (i.e. the first statement changes the list that you are operating upon).

to remove the first 2 cells you should do (my preference)

  {
                gvr.Cells.RemoveAt(0);
                gvr.Cells.RemoveAt(0);
               
            }

or even this would work better than what you have

  {
                gvr.Cells.RemoveAt(1);
                gvr.Cells.RemoveAt(0);
               
            }


if you think about it - it makes more sense..

Try laying out some playing cards on the table and replicating your code operations if you still dont understand what i mean.
0
 

Author Comment

by:Lorna70
ID: 37714080
Thank you so much - I've been tearing my hair out for weeks on this! :-)
0
 
LVL 9

Expert Comment

by:lojk
ID: 37714111
It was a bit of a glaring error but I've been down this road with similar issues so many times before - sometimes you just need a fresh pair of eyes on the subject.

Glad to have saved some of your hair, even if it's too late for mine. ;-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question