View Single Post
  #2 (permalink)  
Old April 24th, 2008, 04:47 PM
surfer5 surfer5 is offline
Wrox Author
 
Join Date: Sep 2006
Location: Tallahassee, FL, USA.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to surfer5 Send a message via AIM to surfer5 Send a message via MSN to surfer5 Send a message via Yahoo to surfer5
Default

Hey Frank-

Let me just say that the chapter you are reading was probably my favorite to write. I continue to preach the merits of the adapters to all that will listen. I am co-authoring another book on SharePoint design and I just finished writing the chapter on how to integrate the adapters inside SharePoint. I sincerely believe these to be some of the coolest enhancements out there.

Now, back to your question. What you are trying to do is, in my opinion, exactly the kind of things that you should be trying to do in the adapters. Make them work the way you want them to.

Now I have never tried to do what you are suggesting so I am just thinking out loud here. But here is what I think.

In the GridViewAdaptar.cs class file, there is a section called WriteRows(). The basic structure is:

foreach(Gridiew row in rows)
    do some stuff, then:
    foreach(TableCell cell in row.Cells)
        do some more stuff

does that make sense?

so, before the first foreach, i would declare an INT variable, say intColumn, and intantiate it to zero.

then, in the first foreach loop, i would set it to zero again.

then, in the second foreach loop, i increment the variable by 1 for each cell.

something (this is very basic) like this:

int intColumn = 0;
foreach(GridViewRow row in rows)
{
    intColumn = 0;
    foreach(TableCell cell in row.Cells)
    {
        intColumn++;
    }
}

this way, you have access to what column you are on (well, zero-based anyway)

at the end of the second foreach loop, there is a command that looks like this:

cell.CssClass += field.ItemStyle.CssClass;

so, right after that, but before you increment your variable, you might want to insert something like:

if(intColumn = 0)
{
    cell.HorizontalAlign = HorizontalAlign.Center;
}

so what would happen is that your counter would reset itself with each row (which is why you are setting it to zero in the first loop). then, in your second loop, you are incrementing your counter with each column so that you can determine which column you are in. then, finally, when you are on the right column, you are setting the horizontal alignment of just that cell.

this is all theoretical, of course, so i would love to hear if this works for you. and, if not, how it breaks. this is fun for me. :D

-jacob

01000111
01000101
01000101
01001011