Click here to Skip to main content
13,143,774 members (32,296 online)
Click here to Skip to main content


165 bookmarked
Posted 21 Dec 2007

LINQ Challenges and SQL Server Compact Edition

, 25 Mar 2008
Overcoming challenges with LINQ to SQL and using LINQ with SQL Server Compact Edition.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TimeApp.DataAccess;

namespace TimeApp.UI {

	public partial class TaskForm : Form {

		// Fields.
		private Task CurrentTask;
		private bool IsTaskNew;

		public TaskForm() {

		protected override void OnLoad(EventArgs e) {

		public DialogResult ShowDialog(IWin32Window owner, Task task, bool isNew) {
			// Initialize fields and control values first.
			CurrentTask = task;
			IsTaskNew = isNew;

			return ShowDialog(owner);

		public DialogResult ShowDialog(IWin32Window owner, Task task) {
			return ShowDialog(owner, task, false);

		/// <summary>
		/// Initializes the controls on the form to the values of the specified task.
		/// </summary>
		/// <param name="task">The Task to initialize from.</param>
		private void InitializeControlValues() {
			// Fill the combobox with the estimation comparison types.
			cbEstimationComparisonType.DataSource = Enum.GetValues(typeof(EstimationComparisonType));
			cbEstimationComparisonType.SelectedIndex = -1;

			// Set the control values appropriately.
			txtName.Text = CurrentTask.Name;
			txtCode.Text = CurrentTask.Code;
			ctlEstimatedDuration.Duration = CurrentTask.EstimatedDuration;
			cbEstimationComparisonType.SelectedItem = CurrentTask.EstimationComparisonType;
			chkDetectAway.Checked = CurrentTask.DetectAway;
			chkIsBillable.Checked = CurrentTask.IsBillable;
			chkIsComplete.Checked = CurrentTask.IsComplete;
			// Update the UI.
			Text = (IsTaskNew ? "New " : "Edit ") + Text;

		/// <summary>
		/// Updates the current task's values from the form's controls.
		/// </summary>
		private void UpdateTaskValues() {
			// Set the current task values from the controls.
			CurrentTask.Name = txtName.Text.Trim();
			CurrentTask.Code = txtCode.Text.Trim();
			CurrentTask.DetectAway = chkDetectAway.Checked;
			CurrentTask.IsBillable = chkIsBillable.Checked;
			CurrentTask.IsComplete = chkIsComplete.Checked;

		private void TaskForm_FormClosed(object sender, FormClosedEventArgs e) {
			if (DialogResult == DialogResult.OK)



By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Matt Sollars
Web Developer
United States United States
I began programming on my Commodore 64 at around the age of 12. After migrating to DOS and then Windows, I decided to take on the Web. Several languages and platforms later, I have settled in with .NET nicely. I am currently the owner of a software consulting company and lead application developer for a learning-based technology consultation company.

The love of a finished application is usually at war with the desire to improve it as soon as it's released (they're never really finished).

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170915.1 | Last Updated 25 Mar 2008
Article Copyright 2007 by Matt Sollars
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid