Let me begin by outlining my situation. I'm a student and I'm trying to improve my skills, so I'm in the process of teaching myself C#, using visual studio 2010. I haven't taken a course in school specific to C#, so everything I know I've pieced together from previous experience and searching through articles on the internet. I apologize ahead of time if this question and my solution seems somewhat juvenile; as I said I am a student and attempting to teach myself. I'm well aware this may be a plodding implementation.
I'm writing a windows forms application to serve as a fantasy football draft manager. The player data is contained in a table in SQL Server Compact Edition 3.5. What I'm trying to do is to allow a user to pick a player from a listbox to "draft" to their team. The listbox is populated with a SQL query based on the option the user selects (Show all players, show only QBs, etc). In a column in the table is a "PCode" that I planned on using to cross-reference between the user's team and the list of players, that is to say it would be the "key" that allows the program to reference which players are contained in a user's team object and which ones are still available. (I hope that makes sense)
So, here's some code. This is the code that executes upon form load, and all the other versions (show only QBs, show only RBs, etc.) are derived from this.
conn = new SqlCeConnection(connectString);
DataSet dsMasterTable = new DataSet();
dsMasterTable = new DataSet();
daMasterTable = new SqlCeDataAdapter("select pcode, overallrank, position, fname, lname, team from MasterTable where available = 'TRUE' order by overallrank", conn);
SqlCeCommandBuilder cmdBldr = new SqlCeCommandBuilder(daMasterTable);
daMasterTable.Fill(dsMasterTable, tableName);
ArrayList arrayRank = new ArrayList();
ArrayList arrayPos = new ArrayList();
ArrayList arrayFname = new ArrayList();
ArrayList arrayLname = new ArrayList();
ArrayList arrayTeam = new ArrayList();
foreach (DataRow row in dsMasterTable.Tables[0].Rows)
{
arrayRank.Add(row["OverallRank"]);
arrayPos.Add(row["Position"]);
arrayFname.Add(row["FName"]);
arrayLname.Add(row["Lname"]);
arrayTeam.Add(row["Team"]);
}
ArrayList arrayComplete = new ArrayList();
for (int i = 0; i < arrayRank.Count; i++)
{
string buildString;
buildString = Convert.ToString(arrayRank[i]) + " " + Convert.ToString(arrayFname[i]) + " " + Convert.ToString(arrayLname[i])
+ ", " + Convert.ToString(arrayPos[i]) + " - " + Convert.ToString(arrayTeam[i]);
arrayComplete.Add(buildString);
}
string[] listBoxContents = (string[])arrayComplete.ToArray(typeof(string));
lbxDisplay.Items.Clear();
lbxDisplay.Items.AddRange(listBoxContents);
}
As you can see, the function of this code is to put together a string pulling from the columns I want to show the user and enter it into the listbox. The problem I'm running in to is I don't know how to represent the listbox items in a way that I can use them as a key to place a player in a user's team object. Ideally, the user will select a row in the listbox (select a listbox item) and click the "Draft" button. The program would reference which item was selected, get the "PCode" value from either the DataSet or from the listbox item itself, then the user's team object would be updated to reflect the fact that the "PCode" has been added to the user's team. The DataSet would then be updated to make the drafted player unavailable (The bool column "Available" set to FALSE)and the listbox updated to only show the remaining available players.
I think I have stated my difficulties in a way that is understandable. I appreciate anyone who might take the time to help me think through this. I hope I haven't violated any rules of the forum in doing so.
If any clarification is necessary, please let me know. I look forward to hearing from you all and posting again in the future. Thanks!

New Topic/Question
Reply



MultiQuote






|