# CustomCell in Eto.Forms

**URL:** <https://discourse.mcneel.com/t/customcell-in-eto-forms/84101>\
**Category:** Rhino Developer\
**Created:** [May 31, 2019, 7:57am UTC](https://discourse.mcneel.com/t/customcell-in-eto-forms/84101 "2019-05-31T07:57:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dmitriy](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dmitriy/32/764664_2.png) [@Dmitriy](https://discourse.mcneel.com/u/Dmitriy)\
**Post date:** [May 31, 2019, 7:57am UTC](https://discourse.mcneel.com/t/customcell-in-eto-forms/84101/1 "2019-05-31T07:57:54Z")

</div>

Hi guys (especially @curtisw and @dale)  
I have a question related to `CustomCell`.  
I am working with `TreeGridView`, where one column is defined as `CustomCell` (containing only button so far).  
Now, when adding `TreeGridItem` I am using `SetValue` method to assign a value of certain column.  
For `TextBoxCell` it is just like: `mytgi.SetValue(1,"SomeData")`.  
How to assign value to `CustomCell`? Should I use `Create` method of `CustomCell`?  
Any short example would be highly appreciated.

Kind regards,  
Dmitriy

---

<div class="post-metadata">

**Author:** ![curtisw](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/curtisw/32/769477_2.png) [@curtisw](https://discourse.mcneel.com/u/curtisw)\
**Post date:** [May 31, 2019, 4:03pm UTC](https://discourse.mcneel.com/t/customcell-in-eto-forms/84101/2 "2019-05-31T16:03:09Z")

</div>

Hey @Dmitriy,

With the CustomCell you can use (On)ConfigureCell or BindDataContext to hook up the values in the TreeGridItem to the controls.

A sample using OnConfigureCell would look like this:

```auto
class MyCustomButtonCellWithConfigure : CustomCell
{
	protected override Control OnCreateCell(CellEventArgs args)
	{
		return new Button();
	}

	protected override void OnConfigureCell(CellEventArgs args, Control control)
	{
		if (control is Button button && args.Item is TreeGridItem treeItem)
		{
			button.Text = treeItem.GetValue(1) as string;
		}

		base.OnConfigureCell(args, control);
	}
}

```

The drawbacks of this approach is that when your tree node updates, it won’t update the cell value. A way to do that is to use data binding, like so:

```auto
class MyTreeNode : TreeGridItem, INotifyPropertyChanged
{
	string _someTextProperty;
	public string SomeTextProperty
	{
		get => _someTextProperty;
		set
		{
			if (_someTextProperty != value)
			{
				_someTextProperty = value;
				PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SomeTextProperty)));
			}
		}
	}

	public event PropertyChangedEventHandler PropertyChanged;
}

class MyCustomButtonCellWithBinding : CustomCell
{
	protected override Control OnCreateCell(CellEventArgs args)
	{
		var button = new Button();
		button.BindDataContext(c => c.Text, Binding.Property((MyTreeNode m) => m.SomeTextProperty));
		return button;
	}
}

```

Using data binding can also be much more versatile when you have more than one control or property that you are binding values to.

Hope this helps!

Cheers,  
Curtis.

---

<div class="post-metadata">

**Author:** ![Dmitriy](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dmitriy/32/764664_2.png) [@Dmitriy](https://discourse.mcneel.com/u/Dmitriy)\
**Post date:** [June 3, 2019, 2:48pm UTC](https://discourse.mcneel.com/t/customcell-in-eto-forms/84101/3 "2019-06-03T14:48:45Z")

</div>

Thanks, @curtisw  
Works perfectly.

---

<div class="post-metadata">

**Author:** ![Christian\_Hartz](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/christian_hartz/32/671954_2.png) [@Christian\_Hartz](https://discourse.mcneel.com/u/Christian_Hartz)\
**Post date:** [February 3, 2022, 10:24pm UTC](https://discourse.mcneel.com/t/customcell-in-eto-forms/84101/4 "2022-02-03T22:24:54Z")

</div>

Good evening,

works perfect for a textbox, but I cant get it to work with a checkbox. Binding the checkbox.Checked property to a property in the viewmodel.

```auto
checkBox.BindDataContext(c => c.Checked, Binding.Property((AFGridItem m) => m.BooleanProperty));

```

I also tried:

```auto
checkBox.CheckedBinding.BindDataContext((AFGridItem m) => m.BooleanProperty);

```

When clicking the checkbox the property never gets set and remains `NULL`.

Any help would be much appreciated.

Thanks  
Christian

---

<div class="post-metadata">

**Author:** ![Christian\_Hartz](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/christian_hartz/32/671954_2.png) [@Christian\_Hartz](https://discourse.mcneel.com/u/Christian_Hartz)\
**Post date:** [February 25, 2022, 2:04pm UTC](https://discourse.mcneel.com/t/customcell-in-eto-forms/84101/5 "2022-02-25T14:04:03Z")

</div>

Alright,

I changed the code and it seems to work:

```auto
protected override Control OnCreateCell(CellEventArgs args)
{
    if (args.Item is AFGridItem item)
    {
        CheckBox checkBox = new CheckBox
        {
            Enabled = true,
            ThreeState = true,
        };
        if (this.ViewModel.DataSet.IsLocked)
        {
            checkBox.Enabled = false;
        }
        checkBox.CheckedBinding.Bind(item, i => i.BooleanProperty);
        return checkBox;
    }
    else
    {
        return new Label
        {
            Wrap = WrapMode.None,
        };
    }
}

```

Kindest  
Christian

---

<div class="post-metadata">

**Author:** ![Christian\_Hartz](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/christian_hartz/32/671954_2.png) [@Christian\_Hartz](https://discourse.mcneel.com/u/Christian_Hartz)\
**Post date:** [July 7, 2022, 3:58pm UTC](https://discourse.mcneel.com/t/customcell-in-eto-forms/84101/6 "2022-07-07T15:58:23Z")

</div>

Would it be possible to get for the `CustomCell` in the Methods `OnCommitEdit`, `OnCancelEdit` and `OnBeginEdit` not only the `CellEventArgs` but also the embedded `Control`, same as `OnConfigureCell`? The `CustomCell` has a property `Control`, but it is `null`. Is there a way to assign to this (I see a `protected set;`)?

Kindest  
Christian

---

<div class="post-metadata">

**Author:** ![Christian\_Hartz](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/christian_hartz/32/671954_2.png) [@Christian\_Hartz](https://discourse.mcneel.com/u/Christian_Hartz)\
**Post date:** [July 16, 2022, 2:15pm UTC](https://discourse.mcneel.com/t/customcell-in-eto-forms/84101/7 "2022-07-16T14:15:24Z")

</div>

Just getting back to this - it would make things so much easier for me, if I could get access to the control also in the `OnCommitEdit` , `OnCancelEdit` and `OnBeginEdit`.

Any suggestions on this @dale or @curtisw?

Kindest  
Christian

---

<div class="post-metadata">

**Author:** ![curtisw](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/curtisw/32/769477_2.png) [@curtisw](https://discourse.mcneel.com/u/curtisw)\
**Post date:** [August 4, 2022, 7:22pm UTC](https://discourse.mcneel.com/t/customcell-in-eto-forms/84101/8 "2022-08-04T19:22:15Z")

</div>

There’s no way currently to access the control in those events, but I can take a look to see if it can be done. I’ve created [RH-69687](https://mcneel.myjetbrains.com/youtrack/issue/RH-69687) to tackle that.

---

<div class="post-metadata">

**Author:** ![Christian\_Hartz](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/christian_hartz/32/671954_2.png) [@Christian\_Hartz](https://discourse.mcneel.com/u/Christian_Hartz)\
**Post date:** [August 5, 2022, 8:44am UTC](https://discourse.mcneel.com/t/customcell-in-eto-forms/84101/9 "2022-08-05T08:44:35Z")

</div>

Thanks for the reply. Just for my understanding, the `CellEventArgs` have a `Control` property. What is this control if not the custom control you specified in the `OnCreateCell`?

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/c/6/0/c60adf0235ded474bcc3d679d855b7db90a638fe.jpeg)

Kindest  
Christian

---

<div class="post-metadata">

**Author:** ![Christian\_Hartz](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/christian_hartz/32/671954_2.png) [@Christian\_Hartz](https://discourse.mcneel.com/u/Christian_Hartz)\
**Post date:** [December 6, 2022, 5:56pm UTC](https://discourse.mcneel.com/t/customcell-in-eto-forms/84101/10 "2022-12-06T17:56:03Z")

</div>

@curtisw,

I would just like to know, if you had any time to work on this. I would like to get this implemented as we will need it for [this - AntFarm](https://discourse.mcneel.com/t/antfarm-data-management-for-rhino-and-gh-pre-release-out-now/143129).

Kindest  
Christian

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [December 6, 2022, 9:02pm UTC](https://discourse.mcneel.com/t/customcell-in-eto-forms/84101/11 "2022-12-06T21:02:27Z")

</div>

Hi @Christian_Hartz,

I see the release target for this issue is set to 8.x, which means the issue won’t get any attention until after Rhino 8 is released. It’s possible this could get earlier attention - time will tell.

– Dale

---

<div class="post-metadata">

**Author:** ![Christian\_Hartz](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/christian_hartz/32/671954_2.png) [@Christian\_Hartz](https://discourse.mcneel.com/u/Christian_Hartz)\
**Post date:** [November 27, 2023, 12:50pm UTC](https://discourse.mcneel.com/t/customcell-in-eto-forms/84101/12 "2023-11-27T12:50:48Z")

</div>

Hi @dale, @curtisw,

as Rhino 8 is out ;-). Is there a chance of getting this fixed? Would be great.

Kindest  
Christian
