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

Thursday, October 2, 2014

Team Foundation Server could not connect to the database after changing the computer

1. Go to IIS - Team Foundation Server - tfs
2. Select Content View
3. Right click web.config, then Browse
4. Edit web.config, look for the old computer name and replace it with the new one
5. Restart IIS
6. Open TFS Administration Console - Application Tier
7. Change URLs

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);