Wednesday, June 29, 2011

Formating date and time in a datagridview in C#

Hi,
The easiest way to format a datetime variable on a datagridview is to set the cell style. For example:



dataGridView1.Columns[1].DefaultCellStyle.Format = "dd'/'MM'/'yyyy hh:mm:ss tt";


If we only need the time, this is my case, we will write


dataGridView1.Columns[1].HeaderText = "Time";
dataGridView1.Columns[1].DefaultCellStyle.Format = "hh:mm";


Hope help!

Sunday, June 12, 2011

iPhone Notifications with NSNotificationCenter

Hi,

How can we send a message to a function when some event happen? For example, today I was writing a function which download an XML file and when it finish send a notification to another function indicating "hey! do something, I've finished my job".

Well, it's very easy:

1) Add an observer to the defaultCenter
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectorDoSomething) name:@"DoSomething" object:nil];

...

-(void) SelectorDoSomething {
// Code here
}

...


- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}



2) Post the notification from other function (or class)
[[NSNotificationCenter defaultCenter] postNotificationName:@"DoSomething" object:self userInfo:nil];



And... done! You have your notifications working.

Hope help