Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my datagridview somethink like ..this.....
sno date day
1 1/1/2005 Monday
2 7/1/2005 Monday
3 14/1/2005 Monday
4 21/1/2005 Monday
user can change date 14/1/2005 to not lessthan= 7/1/2005 and not greater= than 21/1/2005
can u help me what i have to do for this validation???????

thanks and regards
Lakhan
Posted
Comments
Sunasara Imdadhusen 28-Dec-11 7:38am    
Please start development and then let us know if you have any issue.

Hi,

You need to write a logic for validating Date like.

C#
void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
DateTime StartDate = "7/1/2005";
DateTime EndDate = "21/1/2005"
DateTime enetedDate = dataGridView1.Rows[e.RowIndex].Cells["Date"];

if( enetedDate >=  StartDate &&  enetedDate<= EndDate)
{
//Your logic should be here..
} 
else
{
 MessageBox.Show("Invalid Date!");
  e.Cancel = true;
}
}


Note: Please use DataType conversion before use. because i haven't implemented it.

Thanks,
Imdadhusen
 
Share this answer
 
Comments
Savalia Manoj M 28-Dec-11 7:50am    
Hi Imdadhusen,
Great Solution again....
Thanks Again....
Have a Great Day....
Sunasara Imdadhusen 28-Dec-11 7:50am    
Thanks dear.
Wendelius 28-Dec-11 15:11pm    
Good answer, 5
 
Share this answer
 
Comments
Wendelius 28-Dec-11 15:11pm    
Good links, my 5.
Monjurul Habib 29-Dec-11 0:59am    
thank you
you can use RangeValidatorcontrol where you can set minimumvalue="7/1/2005" and maximumvalue="21/1/2005"
Try
RangeValidator Control[^]
 
Share this answer
 
v2
Comments
[no name] 28-Dec-11 7:28am    
but my dear friend i m talking about window application
RaviRanjanKr 28-Dec-11 7:56am    
so you should mention about your requirement in your question.
Sunasara Imdadhusen 28-Dec-11 7:39am    
You should clarify everything in your question!
[no name] 28-Dec-11 8:17am    
window application
Wendelius 28-Dec-11 15:12pm    
The vote of 1 was totally unnecessary and just because of OP's missing requirements, compensated.
simple get the srno, of the updating row and then compare the before that srno and after that srno. and validate the date you want to update
 
Share this answer
 

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