Friday, August 18, 2006

Getting parent

I have a control embedded in another nested control.

I need to get a parent several levels up (but not all the way up), basically I need to do a recursive search up the parents until I hit a parent that is one of two types - then I want to know which of the two types it was.

I haven't figured out how to do this: it seems that the Parent property of Control is unreliable - sometimes it sets itself, othertimes it is null. I am using ContainerControls so I tried the ParentForm property but this jumps me up all the way to my application form (further up the ancestory tree than I want to go). There is also Form.Owner but my control is not a form.

Right now, I am just manually setting my own propetry as I create each control ( I have to do this for a few different controls along the ancestory line)

Thursday, August 10, 2006

DataGridView - don't highlight selection

If you don't want to highlight the selected row in your DataGridView - maybe the whole grid is read only and you don't want users to be able to highlight a row because you don't do anything special with the highlighted row - here's how to do it:

go to your defaultCellStyle under your DataGridView properties.

Set SelectionBackColor to white (or same color as non-selected rows)

Voila!

Tuesday, August 01, 2006

Error connecting to database

Are you getting this error?

Sqlcmd: Error: Microsoft SQL Native Client: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.

The default solution is here:

http://support.microsoft.com/?kbid=914277&SD=tech

But what if this doesn't work? Or you're not using SQL Server 2005? Or you don't have access to the database and want to try a local solution first?

First:

Disable Simple File Sharing on your computer:
http://compnetworking.about.com/cs/winxpnetworking/ht/winxpsfs.htm

If that doesn't work, try adding the port number to your connection string. For example, change:

servername

to:

servername,1234

also, if you are connecting to a local database try changing the data source in your connection string from:

(local)

to

.\SQLEXPRESS

(This may be true even if you are not using SQLEXPRESS but have it installed on your machine, or used it at one point)

Hope this helps!