GrapeCity.Win.MultiRow.v80 アセンブリ > GrapeCity.Win.MultiRow 名前空間 > PopupCell クラス : PopupValueMember プロパティ |
例外 | 解説 |
---|---|
System.ArgumentException | 指定された値が、Popupプロパティによって指定されたSystem.Windows.Forms.CommonDialogまたはSystem.Windows.Forms.Formの有効なメンバではありません。 |
System.ArgumentNullException | 指定された値がnull 参照 (Visual Basicでは Nothing)です。 |
PopupCellセルでは、このプロパティとPopupプロパティにより、任意の型の値を編集できます。編集フォームまたはダイアログが閉じた後、PopupCellは、フォームのプロパティの値を示すPopupValueMemberを取得し、その値をセルに設定します。たとえば、Color型を編集する場合は、PopupプロパティをSystem.Windows.Forms.ColorDialogに設定し、PopupValueMemberを"Color"に設定します。ColorDialogで赤を選択してダイアログを閉じると、セルの値がColor.Redに変わります。
PopupValueMemberプロパティの値を変更すると、FormattedValueTypeプロパティの値が、フォームの特定のプロパティのプロパティ型に変更されます。このとき、セルの値がFormattedValueTypeに適合していないと、GcMultiRow.DataErrorイベントが発生することがあります。そのため、このプロパティの値を変更するときは、事前に値が適切であることを確認してください。
PopupCell CreateColorPopupCell() { PopupCell popupCell1 = new PopupCell(); // Pop up ColorDialog when click button. popupCell1.Popup = new ColorDialog(); // Use ColorDialog's Color property's value as cell's value. popupCell1.PopupValueMember = "Color"; popupCell1.Name = "Color"; popupCell1.Size = new Size(80, 21); return popupCell1; } void gcMultiRow1_CellFormatting(object sender, CellFormattingEventArgs e) { if (e.CellName == "Color") { if (e.Value != null) { e.CellStyle.BackColor = (Color)e.Value; } } } PopupCell CreateCustomTypePopupCell() { PopupCell popupCell1 = new PopupCell(); // Pop up student edit form when click button. popupCell1.Popup = new StudentEditForm(); // Use student edit form's Student property's value as cell's value. popupCell1.PopupValueMember = "Student"; popupCell1.TextBoxReadOnly = true; popupCell1.Size = new Size(150, 21); return popupCell1; } class StudentEditForm : Form { TextBox idTextBox = new TextBox(); TextBox nameTextBox = new TextBox(); public StudentEditForm() { // Initialize student edit form. FlowLayoutPanel panel = new FlowLayoutPanel(); panel.Size = new Size(150, 200); Label label1 = new Label(); label1.Text = "Student ID:"; Label label2 = new Label(); label2.Text = "Student Name:"; Button okButton = new Button(); okButton.Text = "OK"; okButton.DialogResult = DialogResult.OK; this.AcceptButton = okButton; this.Controls.Add(panel); panel.Controls.Add(label1); panel.Controls.Add(idTextBox); panel.Controls.Add(label2); panel.Controls.Add(nameTextBox); panel.Controls.Add(okButton); this.Text = "Student"; } public Student Student { get { return new Student(idTextBox.Text, nameTextBox.Text); } set { if (value != null) { idTextBox.Text = value.ID; nameTextBox.Text = value.Name; } } } } class Student { public Student(string id1, string name1) { ID = id1; Name = name1; } public string ID; public string Name; public override string ToString() { return "ID:" + ID + " Name:" + Name; } }
Private Function CreateColorPopupCell() As PopupCell Dim popupCell1 As New PopupCell() ' Pop up ColorDialog when click button. popupCell1.Popup = New ColorDialog() ' Use ColorDialog's Color property's value as cell's value. popupCell1.PopupValueMember = "Color" popupCell1.Name = "Color" popupCell1.Size = New Size(80, 21) Return popupCell1 End Function Private Sub gcMultiRow1_CellFormatting(ByVal sender As Object, ByVal e As CellFormattingEventArgs) Handles gcMultiRow1.CellFormatting If e.CellName = "Color" Then If e.Value <> Nothing Then e.CellStyle.BackColor = DirectCast(e.Value, Color) End If End If End Sub Private Function CreateCustomTypePopupCell() As PopupCell Dim popupCell1 As New PopupCell() ' Pop up student edit form when click button. popupCell1.Popup = New StudentEditForm() ' Use student edit form's Student property's value as cell's value. popupCell1.PopupValueMember = "Student" popupCell1.TextBoxReadOnly = True popupCell1.Size = New Size(150, 21) Return popupCell1 End Function Private Class StudentEditForm Inherits Form Private idTextBox As New TextBox() Private nameTextBox As New TextBox() Public Sub New() ' Initialize student edit form. Dim panel As New FlowLayoutPanel() panel.Size = New Size(150, 200) Dim label1 As New Label() label1.Text = "Student ID:" Dim label2 As New Label() label2.Text = "Student Name:" Dim okButton As New Button() okButton.Text = "OK" okButton.DialogResult = DialogResult.OK Me.AcceptButton = okButton Me.Controls.Add(panel) panel.Controls.Add(label1) panel.Controls.Add(idTextBox) panel.Controls.Add(label2) panel.Controls.Add(nameTextBox) panel.Controls.Add(okButton) Me.Text = "Student" End Sub Public Property Student() As Student Get Return New Student(idTextBox.Text, nameTextBox.Text) End Get Set(ByVal value As Student) If Not value Is Nothing Then idTextBox.Text = value.ID nameTextBox.Text = value.Name End If End Set End Property End Class Private Class Student Public Sub New(ByVal id1 As String, ByVal name1 As String) ID = id1 Name = name1 End Sub Public ID As String Public Name As String Public Overloads Overrides Function ToString() As String Return "ID:" + ID + " Name:" + Name End Function End Class