Solved

Disabling of Header Click in Datagrid

Posted on 2016-10-06
2
18 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
2 Comments
 
LVL 33

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Events in static methods 3 50
Problem to error 4 47
Angular - break the dataset in chunks? 7 40
Help with C#, MVC, razor. 6 23
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now