Posts

Showing posts from April, 2015

Winforms DataGridView Notes

It is not often when I have to go and create a DataGridView in Winforms so here are some notes.   Sadly we are stuck in .net 2.0. I find it easier to add the columns manually through the designer that the datagridview will hold.  Ids, text fields, buttons, etc.  I have a custom CalendarColumn as well.  The main fields of the columns in the dgv that are used are the HeaderText, Visible, DefaultCellStyle->Format, DataPropertyName, Name, AutoSizeMode, and Width.  In case of Button UseColumnTextForButtonValue (remember to have the FlatStyle = Standard). When accessing data, the values could be nothing or DBNull.value, depending if it is a new row or not.  So will need a lot of testing for DBNull or Nothing. Adding data to dgv could be done inside the dgv, but having fields outside to add to the grid is feasible as well. Modifing inside or outside grid can work. Deleting seems to work well inside.   Rebinding works well after a changing data (aka getting datatable and setting it

IIF Evaluates Both Cases

Forgot about this little wtf with IIF() in vb.net.  It will evaluate both cases.  Another reason why I like c# better than vb.net. The following snippet will throw an "Invalid Cast Exception cannot convert DbNull to String" when the value of that cell is DbNull.  Even though you would think it would just return Nothing in that case.                 sIncident.ExpireDate = IIf(row.Cells("colExpireDate").Value Is DBNull.Value, Nothing, DateTime.Parse(row.Cells("colExpireDate").Value)) So an alternative is just to use If ..else  If (row.Cells("colExpireDate").Value Is DBNull.Value) Then                     sIncident.ExpireDate = Nothing                 Else                     sIncident.ExpireDate = DateTime.Parse(row.Cells("colExpireDate").Value)                 End If

Change Ports On Two Web Sites

So I have two example programs websites, however they are looking for a certain port.  The location of the port for a Web Site type project is in the solution file.  After changing them for both projects I was able to see that it was working and going between the two sites in the two visual studios. http://stackoverflow.com/questions/22822209/changing-project-port-number-in-visual-studio-2013

MIME Types and [MyProgram] Cannot Open this File Type!

Never understood what the MIME type was before and that came to bite me in the ass today.  Basically we had this application that reads this file we generate from a site and it automatically opens in the browser.  Well the issue our clients were having was that the file was not recognized and the application would not open it. What changed was that the program had an update that deprecated the existing extension and instead changed it to a new one.  So after I changed the file extension to the new one I also had to change the mime type of the file to the new format so the program would open, loading the data. http://en.wikipedia.org/wiki/MIME

The name 'ConfigurationManager' does not exist in the current context

I have encountered this several times, and it irritates me each time.  Sometimes I remember it sometimes I do not.  Not sure why you have to go and manually add the System.Configurations to the References as well as adding the using statement for it.  http://stackoverflow.com/questions/1274852/the-name-configurationmanager-does-not-exist-in-the-current-context Oh and this is one case where vb.net is easier than c# (one of the few).  C# syntax would be ConfigurationManager.ConnectionStrings["dsn"].ConnectionString;, while vb.net syntax would for example be ConfigurationManager.AppSettings("dsn").

Cannot use namespace even though I added it

http://stackoverflow.com/questions/4228992/namespace-not-recognized-even-though-it-is-there Bascially need to check the .net version and that you do NOT have "Client" in the title. Then need to rebuild.

Making a Sql Table Read Only

http://www.mssqltips.com/sqlservertip/2711/different-ways-to-make-a-table-read-only-in-a-sql-server-database/ Example: ALTER TABLE tblEvents WITH NOCHECK ADD CONSTRAINT chk_read_only_tblEvent CHECK( 1 = 0 )