|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
NEWBIE: DataGrid CheckBox QuestionBefore I begin with the long winded explanation and question I have researched this through this forum and google and haven't found any answers. I throw myself on the mercy of this group. Admittedly I don't have much background with c# and the code I am using is mostly borrowed from a number of sources. With that said I am trying to fill a DataGrid with an ArrayList of Project objects in a Windows Form. I am able to load the ArrayList into the DataGrid along with a desired boolean checkbox in the first column. However, when I change the value of the checkbox and then click a button to test whether it is true or false the checkbox value reverts back to its default. There are a number of things going on (as far as I can tell with my limited knowledge). Some assumptions: 1) I don't have a formal dataset (datatable) defined because I load the datagrid directly from the arraylist. 2) I defined the checkbox via a DataGridTableStyle using DataGridBoolColumn. In order to create an actual checkbox within the row I need to give each checkbox a default value. I have defined my Project object as follows to accomplish setting a default value for each checkbox: public Project( bool select, int projectID, string projectName, string projectSponsor, string projectCategory, DateTime startDate, DateTime finishDate, string orgPriority, string divPriority, string upsPriority, int percentComplete, int percentWorkComplete ) select is the boolean that I set to false for each Project object. I load the ArrayList with Project as follows where row is my arraylist: row.Add(new Project( false, iProjectID, sProjectName[0], sProjectSponsor, sProjectCategory, Convert.ToDateTime(sStartDate), Convert.ToDateTime(sEndDate), sOrgPriority, sDivPriority, sUPSPriority, iPercentComplete, iPercentWorkComplete)); I bind the arraylist to my DataGrid where projectData is the DataGrid: projectData.DataSource = row; I then define a series of DataGridTableStyles where the first one is DataGridBoolColumn: DataGridBoolColumn cb = new DataGridBoolColumn(); cb.MappingName = "Select"; cb.HeaderText = "Select"; ((DataGridBoolColumn)cb).ReadOnly = false; cb.Width = Convert.ToInt16(0.25 * colwidth); // Add Column to GridColumnStyles tableStyle.GridColumnStyles.Add(cb); After I have done all this, everything appears correctly within the DataGrid. When I check a checkbox a little pencil shows up in the row header. When the checkbox cell loses focus the value reverts back to the default value set in my Project object. As I mentioned above, I don't seem to have a named dataset/datatable because I am loading directly from an arraylist. What am I doing wrong? Thanks in advance, Kevin
Other interesting topics
byte[] to enter key
call program windows in my application like a child HttpWebRequest: black hole XML over GPRS - Is this a good idea????? Screen Scrolling with Keyboard, cut, copy and past Hi I want to Add to an existing xmLDocument an Element . How? I was searching around for a free C# profiler. Issue with using DOS commands in C# Error: The type or namespace name 'NLog' could not be found Visual Studio® 2005 SP1 |
|||||||||||||||||||||||