Menu

#1 ControlColumn ControlFactory directions

open
nobody
None
5
2008-04-02
2008-04-02
No

Hello,

I am in need of help implementing ControlFactory for a Control Column.

I have created a ControlFactory that will create a TextBox, ListBox or CheckBox based on the cell.Data.

However, I need the following assistance...

1) When the ControlColumn is resized, what is the best method to resize the controls in the column? I tried overriding the UpdateControl method and (a) recreating the control and also (b) changing the properties (size) on the control, but the painting of the control flickers with the old control. It seems the old control in (a) is not disposed or (b) something I can't explain.
1.1) Who is responsible for disposing the ols control when using UpdateControl()? From what I read, I assumed Table or TableModel would handle the disposing.
1.2) In general, when a property of the Table, TableModel, ColumnModel, Row, or Cell changes, what is the best method to update a control in a ControlColumn that I create?

2) If I have the Table, TableModel, Row or ColumnModel, and know the Cell position, how can I get to the Control that the ControlFactory created?
2.1) Or, is functionality limited (or best left) to UpdateControl?

3) Is there a better way to get the current cell width and height, other than...
int height = cell.Row.Height;
int width = cell.Row.TableModel.Table.ColumnModel.Columns[ cell.Index ].Width;

4) I have not tried yet, but I assume, that I will need to attached my own GotFocus, LostFocus, Changed events to Controls created by ControlFactory (I'm 99% sure, but double-checking).
4.1) If I do, during the event, I get the sender (which is the control), I would use Table.GetContainingCell( control ) to access the container Cell, correct?

Thanks,
Keith McCreery

//
// Code notes... Both cell.Tag and cell.Data have been tried.
// Yes, I have a if ( ... || ( false ) ) as a placeholder for additional code later...
//

public class DataValuesControlFactory : XPTable.Models.ControlFactory
{
public DataValuesControlFactory()
{
}

public override System.Windows.Forms.Control GetControl( XPTable.Models.Cell cell )
{
int height = cell.Row.Height;
int width = cell.Row.TableModel.Table.ColumnModel.Columns[ cell.Index ].Width;

if ( cell.Tag is csi.Utility.Datapoints.Datapoint )
{
csi.Utility.Datapoints.Datapoint tag = cell.Tag as csi.Utility.Datapoints.Datapoint;

if ( ( tag.Validation.DataTypeName.ToUpper() == "YES/NO" ) || ( false ) )
{
System.Windows.Forms.CheckBox control = new System.Windows.Forms.CheckBox();

if ( ( cell.Text == "1" ) || ( cell.Text.ToUpper() == "YES" ) || ( cell.Text.ToUpper() == "TRUE" ) )
control.Checked = true;
else
control.Checked = false;

control.Width = width;
control.Height = height;
//control.Size = new Size( width, height );

return control;
}
else if ( tag.Validation.ValidValues.ValueList.Count > 0 )
{
System.Windows.Forms.ComboBox control = new System.Windows.Forms.ComboBox();

foreach ( csi.Engine.Containers.DataValidationInfo.ValueInfo v in tag.Validation.ValidValues.ValueList )
{
control.Items.Add( v.Label );
if ( cell.Text.ToUpper() == v.Value.ToUpper() )
control.Text = v.Label;
}

control.Width = width;
control.Height = height;
//control.Size = new Size( width, height );

return control;
}
else
{
System.Windows.Forms.TextBox control = new System.Windows.Forms.TextBox();

control.Text = cell.Text;
control.BorderStyle = BorderStyle.None;

control.Width = width;
control.Height = height;
//control.Size = new Size( width, height );

return control;
}
}
else
{
System.Windows.Forms.TextBox control = new System.Windows.Forms.TextBox();

control.Text = cell.Text;
control.BorderStyle = BorderStyle.None;

control.Width = width;
control.Height = height;
//control.Size = new Size( width, height );

return control;
}

return null;
}

public override System.Windows.Forms.Control UpdateControl( XPTable.Models.Cell cell, Control control )
{
/*
System.Windows.Forms.Control newControl = null;

int height = cell.Row.Height;
int width = cell.Row.TableModel.Table.ColumnModel.Columns[ cell.Index ].Width;

if ( ( control.Height != height ) || ( control.Width != width ) )
{
newControl = control;
newControl.Width = width;
newControl.Height = height;
}

return newControl;
*/
int height = cell.Row.Height;
int width = cell.Row.TableModel.Table.ColumnModel.Columns[ cell.Index ].Width;
control.Height = height;
control.Width = width;

return null;
}

}

Discussion