Solved

Disabling of Header Click in Datagrid

Posted on 2016-10-06
2
43 Views
Last Modified: 2016-11-28
Dear Sir/Madam,

Please be kind enough to tell me how I can disable header click after adding calendar and time using numeric updown inside datagridview.

Because both time and date clicks on the Header.

Any help would be greatly appreciated.

Kind Regards,
Indunil Sanjeewa
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Accepted Solution

by:
it_saige earned 500 total points
ID: 41834034
Assuming this is in reference to: https:/Q_28974717.html

Add a check to ensure that the event row index is not -1 to the OnCellClick event; e.g. -
private void OnCellClick(object sender, DataGridViewCellEventArgs e)
{
	if (sender is DataGridView)
	{
		var grid = sender as DataGridView;
		// If the grid has rows and the cell that sent the event is not in the header row
		if (grid.Rows.Count > 0 && e.RowIndex != -1)
		{
			var dtp = default(DateTimePicker);
			var columns = new[] { "startdate", "starttime", "enddate", "endtime" };
			var column = grid.Columns[e.ColumnIndex].Name;
			if (columns.Any(x => x.Equals(column, StringComparison.OrdinalIgnoreCase)))
			{
				dtp = new DateTimePicker();
				grid.Controls.Add(dtp);
				dtp.Format = column.IndexOf("time", StringComparison.OrdinalIgnoreCase) > -1 ? DateTimePickerFormat.Time : DateTimePickerFormat.Short;
				if (dtp.Format.Equals(DateTimePickerFormat.Time))
					dtp.ShowUpDown = true;
				var rectangle = grid.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
				dtp.Size = new Size(rectangle.Width, rectangle.Height);
				dtp.Location = new Point(rectangle.X, rectangle.Y);
				//dtp.CloseUp += OnCloseUp;
				dtp.Leave += OnLeave;
				dtp.Validating += OnValidating;
				dtp.Visible = true;
			}
		}
	}
}

Open in new window


-saige-
1
 
LVL 14

Expert Comment

by:frankhelk
ID: 41903877
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: it_saige (https:#a41834034)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

frankhelk
Experts-Exchange Cleanup Volunteer
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question