Had all sorts of problems trying to get the Winforms CheckedListBox to data bind properly. Found this article and code sample that helped:
http://www.codeproject.com/cs/combobox/ExCheckedListBox.asp
Just needed to add a custom function in T-SQL for the reports:
–select * from fnGetCites(4)
ALTER FUNCTION fnGetCites
(
@Code INT
)
RETURNS @ReturnTable TABLE (CityID INT, CityName VARCHAR(50))
AS BEGIN
DECLARE @CityID INT
DECLARE @CityName VARCHAR(50)
–loop in all items in the cites table
DECLARE crsr CURSOR FOR SELECT CityID,
CityName
FROM Cities
OPEN crsr
FETCH NEXT FROM crsr INTO @CityID, @CityName
WHILE @@FETCH_STATUS = 0 BEGIN
IF (@Code & POWER(2, @CityID- 1)) = POWER(2, @CityID – 1)
–ADD TO return table
INSERT INTO @ReturnTable
VALUES(@CityID, @CityName)
FETCH NEXT FROM crsr INTO @CityID, @CityName
END
CLOSE crsr
DEALLOCATE crsr
RETURN
END