Winforms TableLayoutPanel adding rows programmatically

I just did this last week. Set the GrowStyle on the TableLayoutPanel to AddRows or AddColumns, then your code should work: // Adds “myControl” to the first column of each row myTableLayoutPanel.Controls.Add(myControl1, 0 /* Column Index */, 0 /* Row index */); myTableLayoutPanel.Controls.Add(myControl2, 0 /* Column Index */, 1 /* Row index */); myTableLayoutPanel.Controls.Add(myControl3, 0 … Read more

How do you modify the web.config appSettings at runtime?

You need to use WebConfigurationManager.OpenWebConfiguration(): For Example: Dim myConfiguration As Configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(“~”) myConfiguration.ConnectionStrings.ConnectionStrings(“myDatabaseName”).ConnectionString = txtConnectionString.Text myConfiguration.AppSettings.Settings.Item(“myKey”).Value = txtmyKey.Text myConfiguration.Save() I think you might also need to set AllowLocation in machine.config. This is a boolean value that indicates whether individual pages can be configured using the element. If the “allowLocation” is false, it cannot be … Read more

Create JPA EntityManager without persistence.xml configuration file

Is there a way to initialize the EntityManager without a persistence unit defined? You should define at least one persistence unit in the persistence.xml deployment descriptor. Can you give all the required properties to create an Entitymanager? The name attribute is required. The other attributes and elements are optional. (JPA specification). So this should be … Read more

Why is Class.newInstance() “evil”?

The Java API documentation explains why (http://java.sun.com/javase/6/docs/api/java/lang/Class.html#newInstance()): Note that this method propagates any exception thrown by the nullary constructor, including a checked exception. Use of this method effectively bypasses the compile-time exception checking that would otherwise be performed by the compiler. The Constructor.newInstance method avoids this problem by wrapping any exception thrown by the constructor … Read more

How permission can be checked at runtime without throwing SecurityException?

You can use Context.checkCallingorSelfPermission() function for this. Here is an example: private boolean checkWriteExternalPermission() { String permission = android.Manifest.permission.WRITE_EXTERNAL_STORAGE; int res = getContext().checkCallingOrSelfPermission(permission); return (res == PackageManager.PERMISSION_GRANTED); }

Compile time vs Run time Dependency – Java

Compile-time dependency: You need the dependency in your CLASSPATH to compile your artifact. They are produced because you have some kind of “reference” to the dependency hardcoded in your code, such as calling new for some class, extending or implementing something (either directly or indirectly), or a method call using the direct reference.method() notation. Run-time … Read more

Rails: convert UTC DateTime to another time zone

time.in_time_zone(time_zone) Example: zone = ActiveSupport::TimeZone.new(“Central Time (US & Canada)”) Time.now.in_time_zone(zone) or just Time.now.in_time_zone(“Central Time (US & Canada)”) You can find the names of the ActiveSupport time zones by doing: ActiveSupport::TimeZone.all.map(&:name) # or for just US ActiveSupport::TimeZone.us_zones.map(&:name)

Can a program depend on a library during compilation but not runtime?

A compile-time dependency is generally required at runtime. In maven, a compile scoped dependency will be added to the classpath on runtime (e.g. in wars they will be copied to WEB-INF/lib). It is not, however, strictly required; for instance, we may compile against a certain API, making it a compile-time dependency, but then at runtime … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)