Xamarin IOS DataGrid - setting column width?


#1

Hi, I am working on Xamarin IOS DataGrid and I am trying to set the width of grid columns programmatically.

I am setting therefore in code the width of a grid column to 25 points, like:

SDataGridColumn UD = new SDataGridColumn("U", "UD");
UD.Width = NSNumber.FromInt32(25);

However on display the width of the column is not 25 points but much wider. I have also tried to set the grid default column properties to something smaller like, this was taken from a similar forum topic:

this.FFADataGrid.DefaultColumnWidth = NSNumber.FromInt32(20);
this.FFADataGrid.MinimumColumnWidth = NSNumber.FromInt32(20);

but also this does not work. Can you please let me know how I can correctly set the required column width?

Thank you,


#2

Hi,

There’s a minimumWidth property on SDataGridColumn which should accomplish what you’re looking for.

Alternatively, if you want to apply that minimum width to every column there’s a minimumColWidth property on ShinobiDataGrid.

I hope that helps!

Sam


#3

Hi, thanks for response

Unfortunately I have also tried the suggested solution but the same result, there is no way whatsoever I can set the width of columns in the grid to the desired size. Unless I am doing something terribly wrong this is a real shortcoming. Furthermore, I have also discovered that I am also unable to set the alignment of the column cells in the desired way. Setting the column alignment property to let’ say center has no effect at all!

For your reference I have tried all of these using your xamarin sample “RenderingDynamicData” under xamarin->samples->DataGrids. You can try to implement these on your own copy of the sample to observe the behaviour.

For example setting the code for the bid column in your sample as follows produces unexpected results:

SDataGridColumn bidColumn = new SDataGridColumn("Bid");
bidColumn.Width = 55;
bidColumn.CellStyle.TextAlignment = UITextAlignment.Center;
grid.AddColumn(bidColumn);

I would appreciate your further feedback on what is implemented in the wrong way.

Regards,

George


#4

Hi just a quick message to let you know I’ll investigate this issue later today.

I didn’t have the same issues you had setting the column widths using the objective-c version of our framework, so there appears to be something a little strange going on there.

Hopefully we’ll be able to determine what the issue is :).

Sam


#5

I’ve taken a look at the sample you mentioned.

I couldn’t replicate your issue with either the alignment or the column width, though your issue may be to do with you suppyling an integer type to columnWidth when it should be an NSNumber:

SDataGridColumn bidColumn = new SDataGridColumn("Bid");
bidColumn.Width = new NSNumber(255);
bidColumn.CellStyle.TextAlignment = UITextAlignment.Center;
grid.AddColumn(bidColumn);

I hope that helps solve your problem.

Kind regards,

Sam


#6

Hi Sam.

I forgot to mention that the sample appears to work fine if the target platform is an Ipad, but it does not work for Iphone, column widths and aligments do not behave propery if the target platform is an Iphone no matter how you set the column width… 

If you are kind enough maybe you can look at the problem replication for Iphone.

Regards,

George


#7

Hi hipath,

I ran the RenderingDynamicData on the iPhone simulator and couldn’t see an issue for me (I set a large column width and the set the alignment to center):

Would you mind giving it another go? Also, although it’s unlikely to be an issue, would you mind letting me know which version of grids you are using - just in case it’s a bug from an old version? If you still can’t set the width and alignment, please feel free to send a sample project to info@shinobicontrols.com and we’ll take a look  :laughing:

Kind regards,

Sam