Click here to Skip to main content
11,649,522 members (76,301 online)
Click here to Skip to main content
Add your own
alternative version

DataGridView Custom Headers in VB.NET

, 9 Mar 2009 CPOL 125.8K 6.8K 44
How to give Custom Headers to your DataGridView
DGVHeaderColor.zip
DGVHeaderColor
DGVHeaderColor
DGVHeaderColor.exe
DGVHeaderColor.pdb
DGVHeaderColor.vbproj.user
DGVHeaderColor.vshost.exe
My Project
Application.myapp
Settings.settings
Resources
AquaBall Blue.png
Button Gray Stripe 01 050.png
DGVHeaderColor.suo
Docs
Gradient ColumnHeader_files
4BBCD906-6DAD-4443-8F0B-525208645B30.jpg
add.gif
AddTo_Blink.png
AddTo_Delicious.png
AddTo_Digg.png
AddTo_Facebook.png
AddTo_Furl.png
AddTo_Google.png
AddTo_Live.png
AddTo_MrWong.png
AddTo_Newsvine.png
AddTo_Reddit.png
AddTo_Simpy.png
AddTo_stumbleupon.png
AddTo_Technorati.png
AddTo_Yahoo.png
ajax-loader.gif
BE.gif
discuss.gif
forum_faq.gif
forum_newmsg.gif
forum_search.gif
GradientColumnheader.png
javaduke.jpg
LAMP.GIF
link.png
logo225x90.gif
mail.gif
member_sm.gif
MonthlyComp.png
msg_admin.gif
msg_answer.gif
msg_general.gif
msg_joke.gif
msg_news.gif
msg_question.gif
msg_rant.gif
pollcol.gif
print.gif
red.gif
report.gif
ServeHTML_data
developer_express_60Free-Controls-150x80.swf
ServeHTML_data_002
B3424356_data
crystal-160x600.swf
ServeHTML_data_003
Dundas_468x60_Chart.swf
ServeLinks_data
smartclient24.jpg
smiley_confused.gif
smiley_laugh.gif
smiley_OMG.gif
smiley_smile.gif
smiley_wink.gif
t.gif
thumbs_down.gif
thumbs_up.gif
t_002.gif
watchon.png
white.gif
function social() {
	this.txtVersion = "1.2";
	this.addtoInterval = null;
	this.popupWin = '';
	this.addtoMethod=1;
	this.AddTitle=null;
	this.AddURL=null;
	this.Horizontal=false;
	this.Showname=false;
	
	this.sns=[
	 {name:'Digg',			image: 'AddTo_Digg.png',		url: 'http://digg.com/submit?',				urlVar: 'url',	titleVar: '',		noteVar: '',	returnVar: '',	otherVars: '&phase=2' },
	 {name:'Del.icio.us',	image: 'AddTo_Delicious.png',	url: 'http://del.icio.us/post?',			urlVar: 'url',	titleVar: 'title',	noteVar: '',	returnVar: '',	otherVars: '' },
	 {name:'Google',		image: 'AddTo_Google.png',		url: 'http://www.google.com/bookmarks/mark?',		urlVar: 'bkmk',	titleVar: 'title',	noteVar: '',	returnVar: '',	otherVars: '&op=edit' },
	 {name:'Windows Live',	image: 'AddTo_Live.png',		url: 'https://favorites.live.com/quickadd.aspx?', urlVar: 'url', titleVar: 'title',	noteVar: '',	returnVar: '',	otherVars: '&marklet=1&mkt=en-us&top=1' },
	 {name:'Yahoo! MyWeb',	image: 'AddTo_Yahoo.png',		url: 'http://myweb2.search.yahoo.com/myresults/bookmarklet?', urlVar: 'u', titleVar: 't',	noteVar: '', returnVar: '', otherVars: '&d=&ei=UTF-8' },
	 {name:'Technorati',	image: 'AddTo_Technorati.png',	url: 'http://technorati.com/faves?',		urlVar: 'add',	titleVar: '',		noteVar: '',	returnVar: '',	otherVars: '' },
	 {name:'Blink',			image: 'AddTo_Blink.png',		url: 'http://www.blinklist.com/index.php?', urlVar: 'url', titleVar: 'title', noteVar: 'description', returnVar: '', otherVars: '&Action=Blink/addblink.php' },
	 {name:'Facebook',		image: 'AddTo_Facebook.png',	url: 'http://www.facebook.com/sharer.php?', urlVar: 'u', titleVar: 't', noteVar: '', returnVar: '', otherVars: '' },
	 {name:'Furl',			image: 'AddTo_Furl.png',		url: 'http://www.furl.net/storeIt.jsp?',	urlVar: 'u',	titleVar: 't',		noteVar: '',	returnVar: '',	otherVars: '' },
	 {name:'Simpy',			image: 'AddTo_Simpy.png',		url: 'http://simpy.com/simpy/LinkAdd.do?',	urlVar: 'href',	titleVar: 'title',	noteVar: 'note', returnVar: '_doneURI', otherVars: '&v=6&src=bookmarklet' },
	 {name:'Reddit',		image: 'AddTo_Reddit.png',		url: 'http://reddit.com/submit?',			urlVar: 'url',	titleVar: 'title',	noteVar: '',	returnVar: '',	otherVars: '' },
	 {name:'Newsvine',		image: 'AddTo_Newsvine.png',	url: 'http://www.newsvine.com/_wine/save?',	urlVar: 'u',	titleVar: '',		noteVar: '',	returnVar: '',	otherVars: '&popoff=0' },
	 {name:'Stumbleupon',	image: 'AddTo_stumbleupon.png',	url: 'http://www.stumbleupon.com/submit?',	urlVar: 'url',	titleVar: 'title',		noteVar: '',	returnVar: '',	otherVars: '' },
	 {name:'Mr. Wong',		image: 'AddTo_MrWong.png',		url: 'http://www.mister-wong.com/index.php?',urlVar: 'bm_url',	titleVar: 'bm_description',	noteVar: '', returnVar: '', otherVars: '&action=addurl' }
	];

	this.DrawLink = function(varName, index, cellClass)
	{
		document.write("<a class=\"" + cellClass + "\" title=\"Add this page to " + this.sns[index].name + "\" ");
		document.write("onclick=\"return " + varName + ".addto(" + index.toString() + ");\" href=\"#\"><img align=\"absmiddle\" src=\"/images/" + this.sns[index].image + "\" ");
		document.write("width=\"16\" height=\"16\" border=\"0\" /> ");
		if (this.Showname) document.write(this.sns[index].name);
		document.write("</a> ");
	};

	this.DrawLinks = function (varName, href, title, cols, width, headClass, cellClass) 
	{
		this.AddTitle = title;
		this.AddURL = href;
		if (cols > this.sns.length) {
			if (this.Horizontal)document.write("<span class=\"" + headClass + "\">Add this article to: </span> ");
			for (var i = 0; i < this.sns.length; i++)
			{
				if (!this.Horizontal)document.write("<div>");
				this.DrawLink(varName, i, cellClass)
				document.write(this.Horizontal?" ":"</div>");
			}
		} else {
			document.writeln("<table width=\"" + width.toString() + "\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>");
			document.writeln("<tr><td colspan=\"" + cols.toString() + "\" class=\"" + headClass + "\" height=\"20\">Add this article to:</td></tr>");
			for (var i = 0; i < this.sns.length; i++)
			{
				document.write("<td valign=\"middle\">");
				this.DrawLink(varName, i, cellClass);
				document.writeln("</td>");
				if ( (((i+1)%cols) == 0) && (i != (this.sns.length-1))) document.writeln("</tr><tr>");
			}
			document.writeln("</td></tr></table>");
		}
	};

	this.addtoWin = function(addtoFullURL)
	{
		if (!this.popupWin.closed && this.popupWin.location){
			this.popupWin.location.href = addtoFullURL;
			//this.addtoInterval = setInterval("this.closeAddTo();",1000);
		}
		else{
			this.popupWin = window.open(addtoFullURL,'addtoPopUp','width=770px,height=500px,menubar=1,toolbar=1,status=1,location=1,resizable=1,scrollbars=1,left=0,top=100');
			//this.addtoInterval = setInterval("this.closeAddTo();",1000);
			if (!this.popupWin.opener) this.popupWin.opener = self;
		}
		if (window.focus) {this.popupWin.focus()}
		return false;
	};
	
	// closes the popupWin
	this.closeAddTo = function() {
		if (!this.popupWin.closed && this.popupWin.location){
			if (this.popupWin.location.href == this.AddURL)	//if it's the same url as what was bookmarked, close the win
			this.popupWin.close();
		}
		else {	//if it's closed - clear the timer
			clearInterval(this.addtoInterval)
			return true
		}
	};

	this.addto = function(index){
		if (!this.AddURL) this.AddURL = document.location.href;
		if (!this.AddTitle) this.AddTitle = escape(document.title);

		var addtoFullURL = this.sns[index].url + this.sns[index].urlVar + "=" + this.AddURL + 
			"&" + this.sns[index].titleVar + "=" + this.AddTitle + this.sns[index].otherVars;
		if (this.sns[index].noteVar != "") 
			addtoFullURL = addtoFullURL + "&" + this.sns[index].noteVar + "=" + this.AddTitle;
		if (this.sns[index].returnVar != "")
			addtoFullURL = addtoFullURL + "&" + this.sns[index].returnVar + "=" + this.AddURL;

		switch(this.addtoMethod){
			case 0:	// 0=direct link
				self.location = addtoFullURL
				break
			case 1:	// 1=popup
				this.addtoWin(addtoFullURL);
				break
			default:	
		}
		return false;
	};
	
	this.setupMenu = function() {
	
		var over = false;

		$(document).ready(function(){
			var e=$("#SBI"), m=$("#ATD");
			var pos = document.all?$(e).position():$(e).offset();
			var eWidth = $(e).outerWidth();
			var mWidth = $(m).outerWidth();
			var eHeight = $(e).outerHeight();
			var left = (pos.left + (eWidth - mWidth)/2) + "px";
			var top = eHeight+pos.top + "px";
			$(m).css({ left: left, top: top });

			$(e).hover(
				function() { $(m).stop(true, true).fadeIn('fast'); }, 
				function() { setTimeout( function() { if (!over) $("#ATD").fadeOut('fast');}, 200); }
			);
			$(m).hover( function() { over=true;}, function() { over=false; $(m).fadeOut('fast');} );
		});
	}
	
	function findPosX(obj)
	{
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				if (detect.indexOf("msie") +1)
				{
					var p = getStyle(obj,'position');
					if (p == 'relative') break;
				}
				
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	}

	function findPosY(obj)
	{
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				if (detect.indexOf("msie") +1)
				{
					var p = getStyle(obj,'position');
					if (p == 'relative') break;
				}
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	}	
}

//	checking across domains causes errors - this is to suppress these
//function handleError() {return true;}
//window.onerror = handleError;

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.

License

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

Share

About the Author

Luca Crisi, MCP
Software Developer (Senior)
Italy Italy
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150804.4 | Last Updated 9 Mar 2009
Article Copyright 2009 by Luca Crisi, MCP
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid