Click here to Skip to main content
15,902,198 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my code ...
i have a data grid view which contain two column 1st date and 2nd day(sunday Monday..ans so on)my problem is that as user enter date in fist cell and press enter key cursor should move on next bellow cell and date should increases by 7 day and date column fill with is assosiate date value (Sunday Monday...)


date day
12/5/2005 Monday
19/5/2005 Monday
26/5/2005 Monday
03/6/2005 Monday
10/6/2005 Monday
17/6/2005 Monday this date should not greater than 31/12/2006

please help me friends

thanks and regards
lakhan
Posted
Updated 26-Dec-11 21:53pm
v2

yourDate.ToString("dddd") returns the day as Sunday, Monday...
 
Share this answer
 
Comments
[no name] 27-Dec-11 4:10am    
thanks but ...i know how to convert date to day but i want it on only enter key press event ...........can u help me
use this code

If Asc(e.KeyChar) = 13 Then

dim dt as new Date
dt="26-12-2011"
dim a as integer
a=dt.dayofweek()
dim str as string
if a=1 then
str="Monday"
elseif a=2 then
str="Tuesday"
upto
elseif a=7 then
str="sunday"
end if


msgbox str


end if
 
Share this answer
 
Hello,
I wrote simple Windows form application,
which consists of one Form containing DataGridView1 control with two columns,
when you enter date into cell in the first column and press enter the
value of the cell in the seckond column of the same row becomes the
day of the week based on the entered date,
and the focus moves to cell in the first column of the next row.
I have used the:
DataGridViewCellEndEdit
event that occurs when edit mode for the current cell ends
afther you press enter, or click on other cell in DataGridView control.

Code for Program.cs

C#
/*
 * Created by SharpDevelop.
 * User: Perić Željko
 * Date: 27.12.2011
 * Time: 14:50
 * 
 */
using System;
using System.Windows.Forms;
namespace Date_and_days
{
	/// <summary>
	/// Class with program entry point.
	/// </summary>
	internal sealed class Program
	{
		/// <summary>
		/// Program entry point.
		/// </summary>
		[STAThread]
		private static void Main(string[] args)
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.Run(new MainForm());
		}
		
	}
}


Code for MainForm.cs :

C#
/*
 * Created by SharpDevelop.
 * User: Perić Željko
 * Date: 27.12.2011
 * Time: 14:50
 * 
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace Date_and_days
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
		}
		
		void DataGridView1CellEndEdit(object sender, DataGridViewCellEventArgs e)
		{
			
			//
			// Event occurs when edit mode for the current cell ends,
			// afther you press enter, or click on other cell i DataGridView control
			//
			
			// 
			// Local variables
			//
			DateTime Date;
			int row = 0;
			int	column = 0;
			bool IsDate = false;
			row = dataGridView1.CurrentCell.RowIndex;
			column = dataGridView1.CurrentCell.ColumnIndex;
			
			//
			// If  edit mode ends for the cell in the first column,Date column.
			//
			if (column == 0)
			{
				//
				// Checks if you have entered Date in first column, Date column.
				//
				// IsDate is true if it is Date entered into Date column,
				// the value of the entered date is set out to Date variable,
				// afther that program write the day of the week from entered date into
				// seckond column Day of the week column.
				//
				// else program sets the value of the seckond column to empty string
				//
				IsDate = DateTime.TryParse(dataGridView1.CurrentCell.Value.ToString(),out Date);
				
				if (IsDate)
				{
					dataGridView1[column+1,row].Value = Date.DayOfWeek.ToString();
				}
				
				else
				{
					dataGridView1[column+1,row].Value = String.Empty;
				}
				
			}
		}
	}
}


Code for MainForm.Designer.cs

C#
/*
 * Created by SharpDevelop.
 * User: Perić Željko
 * Date: 27.12.2011
 * Time: 14:50
 * 
 */
namespace Date_and_days
{
	partial class MainForm
	{
		/// <summary>
		/// Designer variable used to keep track of non-visual components.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
		
		/// <summary>
		/// Disposes resources used by the form.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing) {
				if (components != null) {
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}
		
		/// <summary>
		/// This method is required for Windows Forms designer support.
		/// Do not change the method contents inside the source code editor. The Forms designer might
		/// not be able to load this method if it was changed manually.
		/// </summary>
		private void InitializeComponent()
		{
			System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
			this.dataGridView1 = new System.Windows.Forms.DataGridView();
			this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
			this.SuspendLayout();
			// 
			// dataGridView1
			// 
			this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
									this.Column1,
									this.Column2});
			this.dataGridView1.Location = new System.Drawing.Point(12, 12);
			this.dataGridView1.Name = "dataGridView1";
			this.dataGridView1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.dataGridView1.Size = new System.Drawing.Size(540, 230);
			this.dataGridView1.TabIndex = 0;
			this.dataGridView1.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataGridView1CellEndEdit);
			// 
			// Column1
			// 
			dataGridViewCellStyle1.Format = "D";
			dataGridViewCellStyle1.NullValue = null;
			this.Column1.DefaultCellStyle = dataGridViewCellStyle1;
			this.Column1.HeaderText = "Date";
			this.Column1.MaxInputLength = 100;
			this.Column1.Name = "Column1";
			this.Column1.Width = 200;
			// 
			// Column2
			// 
			this.Column2.HeaderText = "Day of the week";
			this.Column2.Name = "Column2";
			this.Column2.Width = 300;
			// 
			// MainForm
			// 
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.ClientSize = new System.Drawing.Size(562, 262);
			this.Controls.Add(this.dataGridView1);
			this.Name = "MainForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Date and days";
			((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
			this.ResumeLayout(false);
		}
		private System.Windows.Forms.DataGridViewTextBoxColumn Column2;
		private System.Windows.Forms.DataGridViewTextBoxColumn Column1;
		public System.Windows.Forms.DataGridView dataGridView1;
	}
}


All the best,
Perić Željko
 
Share this answer
 
v4

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900