Forum Xamarin.Mac


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

NSTextView as a group

codergcoderg Member ✭✭

I want to group NSTextview and access/change their values based on "Tag"? Is this possible?

Eg: I need something like radio button. Where there are 5 textfields, all five will have same name but different Tag value.


  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    Often, but not always you really want a NSTextField, which is a simpler version of NSTextView.

    You can likely assign a common delegate instance for each one and use a tag you set to distinguish (and do whatever custom logic you want).

  • codergcoderg Member ✭✭
    edited March 2020

    Hi Chris,

    How can I create an array of NSTextfield and add all the textfields to an NSBox programmatically?

  • codergcoderg Member ✭✭
    edited March 2020

    I was able to add NSTextFIeld programmatically. But why am I getting "Object reference not set to an instance of an object" error while trying to print the "StringValue" value of my Texfield created programmatically?

    NSTextField[] t = new NSTextField[1];
    public override void ViewDidLoad()

            t[0] = new NSTextField();
            t[0].Frame = new CoreGraphics.CGRect(20, 1, 200, 20);
            t[0].Tag = 0;
            t[0].Identifier = "0";
            t[0].StringValue = "yahoo";
            t[0].Bordered = true;
            t[0].Changed += new EventHandler(testt);


    public void testt(Object sender, EventArgs e) {
    NSTextField check = sender as NSTextField;
    //var check = sender as NSTextField; this is also not working

    System.NullReferenceException: Object reference not set to an instance of an object
    at myProject.ViewController.testt (System.Object sender, System.EventArgs e) [0x00008] in
    /path to my folder /ViewController.cs:125
    at AppKit.NSTextField+_NSTextFieldDelegate.Changed (Foundation.NSNotification notification) [0x00011] in /Library/Frameworks/Xamarin.Mac.framework/Versions/
    at at (wrapper managed-to-native) AppKit.NSApplication.NSApplicationMain(int,string[])
    at AppKit.NSApplication.Main (System.String[] args) [0x00040] in /Library/Frameworks/Xamarin.Mac.framework/Versions/
    at myProject.MainClass.Main (System.String[] args) [0x00007] in
    /path to my folder /Main.cs:57

Sign In or Register to comment.