I guessing that you can easily modify my example to be a ToolPart rather
than rendering directly in the body of the WebPart. So, let me focus on
the crux of your two questions:
1. How do I open a specific SPWeb at a specific SPSite and iterate its
single Event list? and
2. How can I allow the end user to map a color onto the Type field so it
isn't hardcoded?
For the first question, you already have half the code to open a given
SPWeb:
//Get specific specified site Collection
SPSite siteCollection = new SPSite("http://foo");
//Get child Web of Site Collection, if empty string the code
will return the root Web
SPWeb web =
siteCollection.OpenWeb("/absolute/urltothe/childsite");
Always remember to dispose of SPSite and SPWeb objects or your memory
footprint could overcome the server.
For the second question, I wonder if you couldn't create a ToolPart that
used a technique similar to the way that SharePoint lets us order
columns on a ListView. But instead of sequence numbers, you would use
unique colors. You would present a list of Types based upon the unique
values in the Events List and to the right of each Type would be a drop
down list of colors. When the user choose a different color for a given
Type the rest of the drop down lists would reshuffle so that they would
all be unique. You could potentially even reuse Microsoft's JavaScript
for reshuffling the drop downs (I've done that before). Then you would
store a delimited list of values as a custom property for the order of
colors the end user has chosen. If the custom property is empty you use
a canned color sequence, otherwise you use the color order chosen by the
end user. As long as you consistently retrieve the list of Types in the
same sequence you would never actually have to store the Type that was
related to a given color.
I drew up a quick HTML example, the Reorder JavaScript is ripped right
out of SharePoint's ViewEdit.aspx page. Paste the following HTML into a
text file, save it as an HTM and view it in a browser to see this idea
come to life:
<head>
<title>Color Chooser</title>
<script language="JavaScript">
function Reorder(eSelect, iCurrentField, numSelects)
{
var eForm = eSelect.form;
var iNewOrder =
eSelect.selectedIndex + 1;
var iPrevOrder;
var positions = new
Array(numSelects);
var ix;
for (ix = 0; ix < numSelects; ix++)
{
positions[ix] = 0;
}
for (ix = 0; ix < numSelects; ix++)
{
positions[eSelect.form["ViewOrder" + ix].selectedIndex] = 1;
}
for (ix = 0; ix < numSelects; ix++)
{
if (positions[ix] == 0)
{
iPrevOrder = ix + 1;
break;
}
}
if (iNewOrder != iPrevOrder)
{
var iInc = iNewOrder >
iPrevOrder? -1:1
var iMin = Math.min(iNewOrder,
iPrevOrder);
var iMax = Math.max(iNewOrder,
iPrevOrder);
for (var iField = 0; iField <
numSelects; iField++)
{
if (iField != iCurrentField)
{
if
(eSelect.form["ViewOrder" + iField].selectedIndex + 1 >= iMin &&
eSelect.form["ViewOrder" + iField].selectedIndex + 1<= iMax)
{
eSelect.form["ViewOrder" + iField].selectedIndex += iInc;
}
}
}
}
}
</script>
</head>
<body>
<form name="frmViewEdit" method="post">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<th align="left">Type</th>
<th align="left">Color</th>
</tr>
<tr>
<td width="100">Holidays</td>
<td>
<select onchange="Reorder(this,
0, 3)" name="ViewOrder0">
<option
value="1_Holidays" selected="selected">Red</option>
<option
value="2_Holidays">Green</option>
<option
value="3_Holidays">Blue</option>
</select>
</td>
</tr>
<tr>
<td>Timesheets</td>
<td>
<select onchange="Reorder(this,
1, 3)" name="ViewOrder1">
<option
value="1_Timesheets">Red</option>
<option
value="2_Timesheets" selected="selected">Green</option>
<option
value="3_Timesheets">Blue</option>
</select>
</td>
</tr>
<tr>
<td>Paydays</td>
<td>
<select onchange="Reorder(this,
2, 3)" name="ViewOrder2">
<option
value="1_Paydays">Red</option>
<option
value="2_Paydays">Green</option>
<option
value="3_Paydays" selected="selected">Blue</option>
</select>
</td>
</tr>
</table>
</form>
</body>