Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Wednesday, August 14, 2024

C# ToString()[i]

 Carefull about object.ToString()[i]: the output is char type. If you Convert that value to int, you will get chars representation in int. To get the value of the char, the simple way is to convert it to string:

  • .ToString()[i].ToString();

Thursday, January 8, 2015

Click Once application doesn't start on a new Windows User

I have a Click Once application installed on a PC with an admin user. I created another admin user and installed the same app, only to find out that is was crashing: App has stopped working. Problem event name: CLR20r3, System argument exception

The reason:
  • my app uses a DataSet that has a specific locale, let's say X
  • when I created the new user, the setting in Region and Language - Formats - Format wasn't set to X
Resolution:
  • I've changed the Format to X and it works fine

Friday, December 19, 2014

C# combobox duplicate items AutoCompleteSource ListItems

I've found a small problem if you want to use a bind dropdown combobox, that has AutoCompleteMode - Suggest and AutoCompleteSource ListItems: if you have two or more duplicate display members(even with the Value Member different), upon select, lets say, the second duplicate item, the combobox automatically selects the first duplicate item.

To resolve this isue:
Set the comboboxes Causes Validation to False

Tuesday, July 23, 2013

Dummy data in Crystal Report at runtime

When using Crystal Reports, in Design mode, you preview your report by clicking "Main Report Preview".

To bind the report I use:
crDaily1.SetDataSource((DataTable)dtDaily);
crDaily1.SetParameterValue("pPeriod", title);

If I put this code in
private void FormReportDaily_Shown(object sender, EventArgs e)
sometimes the dummy data that appears in "Main Report Preview" is shown at runtime. I really don't know the reason?!.

Resolution:

Put the binding code
crDaily1.SetDataSource((DataTable)dtDaily);
crDaily1.SetParameterValue("pPeriod", title);

in the constructor:
public FormReportDaily()

Thursday, October 4, 2012

Expando Object

The ExpandoObject class enables you to add and delete members of its instances at run time and also to set and get values of these members.

Creating a dynamic instance:
       dynamic Student = new ExpandoObject();
       Student.ID = 1;
       Student.Name = "John";
Student.Grade = 10;


Creating a nested dynamic instance:
       Student.Addess = new ExpandoObject();
       Student.Addess.City = "London";
       Student.Addess.Country = "UK";
       Student.Addess.StreetNo = 123456;
Dynamically binding an Event
Student.Click += new EventHandler(SampleHandler);
 
private void SampleHandler(object sender, EventArgs e)
{
//throw new NotImplementedException();
}
Pass parameter as dynamic.
public void Write(dynamic Student)
{
//do stuff
}

Tuesday, July 10, 2012

Dynamicly add xsi:schemaLocation="location" to XML

// Comment
//create XML
XmlDocument doc = new XmlDocument();

//header
XmlDeclaration decl = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
doc.AppendChild(decl);

//
doc.Schemas.Add("test:schema:v1", "http://sample.com/schema.xsd");
XmlElement decElem = doc.CreateElement("root");
XmlAttribute attr = doc.CreateAttribute("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance");
attr.Value = "test:schema:v1 schema.xsd";
decElem .Attributes.Append(attr);
decElem .SetAttribute("xmlns", "decElem");
doc.AppendChild(docElem);

Friday, March 23, 2012

Error when changing an applications Target Framework from 2.0 to 4.0

I've had a problem with Crystal Reports when changing an applications Target Framework from 2.0 to 4.0 

Error:
Could not load file or assembly 'file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet1\crdb_adoplus.dll' or one of its dependencies. The system cannot find the file specified.

Resolution:
Add the following to app.config:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime Version="v4.0" sku=".NETFramework, Version=v4.0" />
startup>
 
 
System: VS 2010, Crystal Reports 13, Windows 7 x64 

Friday, June 3, 2011

The stub received bad data

"System.Runtime.InteropServices.COMException (0x800706F7): The stub received bad data. (Exception from HRESULT: 0x800706F7)
at Word.Find.Execute("

To work around this issue, follow these steps:

1. Click Start, click Run, type Regedit in the Open box, and then click OK.
2. Locate the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft
3. Right-click the registry key that you located in step 2, click New, and then click Key.
4. Type OleAut, and then press ENTER.
5. Right-click OleAut, click New, and then click DWORD
6. Type DisableShield, and then press ENTER.
7. Right-click DisableShield, and then click Modify.
8. In the Value data box, type 00000001, and then click OK.
9. On the File menu, click Exit to quit Registry Editor.

Note: This workaround disables some security checks that have been implemented in the Windows Server 2003 and Windows XP operating systems. Therefore, we recommend that you use this workaround to test whether the hotfix that this article describes will resolve the problem that you are experiencing. We do not recommend that you use this workaround as a permanent resolution for this problem.

More info:
http://support.microsoft.com/kb/895321/

Monday, September 7, 2009

Exception thrown in Form.Load event is never caught by IDE

You can configure debugger to break on selected exceptions. To do this you need to open Debug -> Exceptions window and ensure that both check boxes are checked (especially check box in "Thrown" column) for the "CLR Exceptions" row.

This means that debugger will intercept and break on the selected exceptions right after they are thrown.

Here is an article about this window: http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/b8c82b79-47d4-42ab-abdb-ff71d67a0022

Source

Monday, April 6, 2009

C# ClickOnce force auto update

To force an auto update in a C# application published with ClickOnce:
    - right click on the solution
    - select Properties
    - under Publish, click Updates button
    - check "Specify a minimum required version for this application"

Monday, February 23, 2009

C# update progressBar from backgroundWorker

private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
    progressBar.BeginInvoke(new MethodInvoker(delegate
       {
            //setProgress(10);
            progressBar1.Value += 10;
        }));
}

Thursday, October 30, 2008

Speed up DataGridView C#

The DataGridView in C# 2005 is very slow for about 15000 records.
Fixes:
  • AutoSizeColumnsMode = Fill;
  • BorderStyle = None;
  • CellBorderStyle = SingleVertical;
  • ColumnHeaderBorderStyle = Single;
  • ColumnHeaderHeightSizeMode = DisableResizing;
  • EditMode = EditProgrammatically;
  • EnableHeadersVisualStyles = False;
  • ReadOnly = True;
  • RowHeadersWidthSizeMode = DisableResizing;
  • ShowCellTooTips = False;

These settings were tested in Visual Studio 2005, in which works very well. I haven't tested them in VS 2008, but I thing they work as well.

Thursday, October 18, 2007

Speed up DataGridView C#

The DataGridView in C# 2005 is very slow for about 15000 records.
Possibly fixes:
  • none at this time

Saturday, June 16, 2007

Get the file that has been clicked after file association in Visual C# Smart Device Application

Yet another problem: if the file association works, how do you know, in a mobile environment, to get the file that has been clicked.

File Association using Visual Studio 2005 Smart Device Cab Project Part 2

I've found the answer to the file association problem


None of my files are signed, and the association still works (when I click a file in the File Explorer, the app is launched).

I have not found a way to export my registry keys from the deployment project (it may be possible using the ccregedt.exe in the CE Remote Tool, but it would just show the installed reg keys).

So, I opened the cab that cabwiz generates and extracted the _setup.xml file. Inside (at the bottom), you'll find the registry sections:

Thanks to vpborza


Sunday, June 10, 2007

File Association using Visual Studio 2005 Smart Device Cab Project

I am trying to make an installer for a SVG viewer for Pocket PCs running Windows Mobile using C# and Windows Mobile 6 SDK.
The installer works, but I am trying to make a file association. When I click on a SVG file the application should start and show that file. I've used registry keys like so:

HKEY_CLASSES_ROOT
|
+ .xxx (Default Value) xxxfile
|
+ xxxfile
|
+ DefaultIcon (Default Value) %InstallDir%\MyApp.exe, 0
|
+ Shell
|
+ Open
|
+ Command (Default value) ""%InstallDir%\MyApp.exe"" ""%%1""

but when I open a SVG file I get this error:
" The file 'filename' cannot be opened. Either it is not signed with a trusted certificate, or one of its components cannot be found. If the problem persists, try reinstalling or restoring the file"

If I open the application directly, it works, and the files are shown, so they are not corrupted.

If anyone has an ideea about what could be wrong, please leave a comment or email me.