public class MyWorksheet : GrapeCity.Windows.SpreadSheet.Data.Worksheet
{
public bool DrawingObjectVisible { get; set; }
public override DrawingObject[] GetDrawingObject(int row, int column, int rowCount, int columnCount)
{
if (row == 0 || !this.DrawingObjectVisible) return base.GetDrawingObject(row, column, rowCount, columnCount);
DrawingObject dobj;
if (column == 7)
{
dobj = new ControlDrawingObject(row, column, new Button() { Content = "..." });
}
else if (column == 6)
{
int value = -1;
object obj = this.GetValue(row, column);
if (obj != null)
{
if (obj is int) value = (int)obj;
else
{
int.TryParse(obj.ToString(), out value);
}
if (value > 2) value = -1;
}
ComboBox control = new ComboBox();
control.Items.Add("Fruit");
control.Items.Add("Vegetable");
control.Items.Add("Food");
if (value >= -1 && value < control.Items.Count)
control.SelectedIndex = value;
control.SelectionChanged += delegate(object sender, SelectionChangedEventArgs e)
{
this.SetValue(row, column, control.SelectedIndex);
};
dobj = new ControlDrawingObject(row, column, control);
}
else if (column == 5)
{
double value = 0;
object obj = this.GetValue(row, column);
if (obj != null)
{
if (obj is double) value = (double)obj;
else if (obj is int) value = (int)obj;
else
{
double.TryParse(obj.ToString(), out value);
}
}
dobj = new ControlDrawingObject(row, column, new ProgressBar() { Value = value, Maximum = 10 });
}
else if (column == 4)
{
bool value = false;
object obj = this.GetValue(row, column);
if (obj != null)
{
if (obj is bool) value = (bool)obj;
else
{
bool.TryParse(obj.ToString(), out value);
}
}
CheckBox control = new CheckBox() { IsChecked = value, Content = "Check Me" };
control.Checked += delegate(object sender, RoutedEventArgs e)
{
this.SetValue(row, column, control.IsChecked);
};
control.Unchecked += delegate(object sender, RoutedEventArgs e)
{
this.SetValue(row, column, control.IsChecked);
};
dobj = new ControlDrawingObject(row, column, control);
}
else if (column == 3)
{
DateTime? value = null;
object obj = this.GetValue(row, column);
if (obj != null)
{
if (obj is DateTime) value = (DateTime)obj;
else
{
DateTime date;
if (DateTime.TryParse(obj.ToString(), out date))
{
value = date;
}
}
}
DatePicker control = new DatePicker() { SelectedDate = value };
control.LostFocus += delegate(object sender, RoutedEventArgs e)
{
this.SetValue(row, column, control.SelectedDate);
};
dobj = new ControlDrawingObject(row, column, control);
}
else if (column == 2)
{
double value = 0;
object obj = this.GetValue(row, column);
if (obj != null)
{
if (obj is double) value = (double)obj;
else if (obj is int) value = (int)obj;
else
{
double.TryParse(obj.ToString(), out value);
}
}
Slider control = new Slider() { Value = value, Maximum = 10 };
control.LostFocus += delegate(object sender, RoutedEventArgs e)
{
this.SetValue(row, column, control.Value);
};
dobj = new ControlDrawingObject(row, column, control);
}
else if (column == 1)
{
string value = this.GetText(row, column);
TextBox control = new TextBox() { Text = value };
control.LostFocus += delegate(object sender, RoutedEventArgs e)
{
this.SetValue(row, column, control.Text);
};
dobj = new ControlDrawingObject(row, column, control);
}
else
{
return base.GetDrawingObject(row, column, rowCount, columnCount);
}
return new DrawingObject[] { dobj };
}
}
|