Wednesday, April 13, 2011

Combobox in datagridviews binding classes and structures

Hi, my problem today is how to show the list of data from an structure into a datagridview using combobox in some columns.

First of all I was surfing on the internet and I found this for enums:

//CF: set to null before setting it to the current to
//clear out previous results
this.bindingSource1.DataSource = null;

this.bindingSource1.DataSource = MyDal.GetDataTable();

void _formatStatusColumn()
{
DataTable dt = new DataTable("Status");

//CF: actually how it's stored in the db.
dt.Columns.Add("Status", typeof(int));
dt.Columns.Add("Status_Name", typeof(string));

//CF: this way I can add or remove enum values, and
//the combo will always reflect the correct values.
foreach(int index in Enum.GetValues(typeof(Status)){
dt.Rows.Add(index, Enum.GetName(typeof(Status), index));
}

//CF: now for the UI column
DataGridViewComboBoxColumn statusColumn =
new DataGridViewComboBoxColumn();

//CF: seems to control where the column is placed.
statusColumn.DisplayIndex = 3;
statusColumn.HeaderText = "Status";

statusColumn.DataPropertyName = "Status";
statusColumn.DataSource = dt;
statusColumn.DisplayMember = "Status_Name";
statusColumn.ValueMember = "Status";

this.dataGridView1.Columns.Add(statusColumn);
}


This was very useful but I need something easier. I have to read a list and show the field in the combobox, so I've changed the code like that:

public void FormatResidenceColumn()
{
if (this.dataGridView1.Columns.Count > 0)
{
DataTable dt = new DataTable("Residence");

dt.Columns.Add("Residence", typeof(int));
dt.Columns.Add("Residence_Name", typeof(string));

this.dataGridView1.Columns.Remove("Residence");

if (Globals.ListOfResidences.Count > 0)
{
foreach (Residence obj in Globals.ListOfResidences)
{
dt.Rows.Add(obj.Id - 1, obj.Alias);
}
}
else
{
// Empty
dt.Rows.Add(0, "Empty");
}

//CF: now for the UI column
DataGridViewComboBoxColumn combColumn =
new DataGridViewComboBoxColumn();

//CF: seems to control where the column is placed.
combColumn.DisplayIndex = 4;
combColumn.HeaderText = "Residencia";

combColumn.DataPropertyName = "Residence";
combColumn.DataSource = dt;
combColumn.DisplayMember = "Residence_Name";
combColumn.ValueMember = "Residence";

this.dataGridView1.Columns.Add(combColumn);
}
}


where I use an global variable named ListOfResidence in this example.

Hope help!!

Sunday, April 3, 2011

How to launch Apple Store from my iphone code

Hi,

Today I will show you a simple function that launches the App Store from your application.

First of all you need to know your app's link for example looking for it in iTunes. And then write a code like this:


-(IBAction) gotoFlightInstrument {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/es/app/instrumental-flight-vuelo/id413551896?mt=8"]];
}


where
"http://itunes.apple.com/es/app/instrumental-flight-vuelo/id413551896?mt=8

is my iTunes app link.

Hope help!

Bye

Saturday, February 26, 2011

Hidden status bar in iphone programatically

Something easy this time. Only one line

[[UIApplication sharedApplication] setStatusBarHidden:YES];


Hope help

Thursday, February 24, 2011

Seting up free Borland C++ 5.5 compile

Hi, Today I need to use the Borland compiler and I've decided to set it up.

If you want to compile from your development directory the way is to create two new files:

bcc32.cfg

-I"C:\Borland\BCC55\Include"
-L"C:\Borland\BCC55\Lib"


ilink32.cfg

-L"C:\Borland\BCC55\Lib"


Now we can compile using:

bcc32 our_file.cpp


Of course, I'm using the default installation path and I set the local variables before.

Bye

Friday, January 28, 2011

Time delay in a iphone development

The easiest way is to delay the thread like this:

[NSThread sleepForTimeInterval:2.0];


Hope help

How to write a UILabel programmatically

I need to add a label that shows a loading string. One way to do it is


UILabel *scoreLabel = [ [UILabel alloc ] initWithFrame:CGRectMake((self.bounds.size.width / 2)-75, 0.0, 150.0, 43.0) ];
scoreLabel.textAlignment = UITextAlignmentCenter;
scoreLabel.textColor = [UIColor whiteColor];
scoreLabel.backgroundColor = [UIColor blackColor];
scoreLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(18.0)];
[self addSubview:scoreLabel];
scoreLabel.text = [NSString stringWithFormat: @"%d", @"Loading..."];


Bye

Sunday, January 16, 2011

How to write text in an iPhone CGContextShowTextAtPoint

Hi,

Today I need to write a text in my iPhone using the CGContextShowTextAtPoint. First problem is that by default the text will appear inverted so we need to tranform it. The solution is for exmaple:

void drawText (CGContextRef myContext, char *title, int x, int y, int w, int h)
{
CGContextSelectFont (myContext, "Arial", h/10, kCGEncodingMacRoman);
CGContextSetRGBFillColor (myContext, 0, 0, 0, 0.99);
CGContextSetTextMatrix(myContext, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));
CGContextShowTextAtPoint (myContext, x, y, title, strlen(title));
}


The key is on the
CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0)
transformation.

Hope help!!