Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6144697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:41:16+00:00 2026-05-23T18:41:16+00:00

I have DataGridView on a different winform and I am trying to get access

  • 0

I have DataGridView on a different winform and I am trying to get access to the DataGridView from main.pas, but I can’t.

I get the following error: “MonoPro.UnitForm” does not contain a definition for “dataGridView1” in expression “fr.dataGridView1”

Here is the code:

Form1.pas with UnitForm Winform with DataGridView

namespace MonoPro.Units;

interface

uses
  System.Drawing,
  System.Collections,
  System.Windows.Forms,
  System.ComponentModel;

type
  UnitForm = partial class
  {$REGION Windows Form Designer generated fields}
  private
    var components: System.ComponentModel.Container := nil;
    dataGridView1: System.Windows.Forms.DataGridView;
    Column3: System.Windows.Forms.DataGridViewTextBoxColumn;
    Column2: System.Windows.Forms.DataGridViewTextBoxColumn;
    Column1: System.Windows.Forms.DataGridViewTextBoxColumn;
    method InitializeComponent;
  {$ENDREGION}
  end;

implementation

{$REGION Windows Form Designer generated code}
method UnitForm.InitializeComponent;
begin
  self.dataGridView1 := new System.Windows.Forms.DataGridView();
  self.Column1 := new System.Windows.Forms.DataGridViewTextBoxColumn();
  self.Column2 := new System.Windows.Forms.DataGridViewTextBoxColumn();
  self.Column3 := new System.Windows.Forms.DataGridViewTextBoxColumn();
  (self.dataGridView1 as System.ComponentModel.ISupportInitialize).BeginInit();
  self.SuspendLayout();
  // 
  // dataGridView1
  // 
  self.dataGridView1.BackgroundColor := System.Drawing.SystemColors.ControlLightLight;
  self.dataGridView1.ColumnHeadersHeightSizeMode := System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  self.dataGridView1.Columns.AddRange(array of System.Windows.Forms.DataGridViewColumn([self.Column1,
      self.Column2,
      self.Column3]));
  self.dataGridView1.Location := new System.Drawing.Point(12, 12);
  self.dataGridView1.Name := 'dataGridView1';
  self.dataGridView1.RowHeadersVisible := false;
  self.dataGridView1.Size := new System.Drawing.Size(795, 221);
  self.dataGridView1.TabIndex := 0;
  // 
  // Column1
  // 
  self.Column1.HeaderText := 'Column1';
  self.Column1.Name := 'Column1';
  // 
  // Column2
  // 
  self.Column2.HeaderText := 'Column2';
  self.Column2.Name := 'Column2';
  // 
  // Column3
  // 
  self.Column3.HeaderText := 'Column3';
  self.Column3.Name := 'Column3';
  // 
  // UnitForm
  // 
  self.ClientSize := new System.Drawing.Size(819, 245);
  self.Controls.Add(self.dataGridView1);
  self.Name := 'UnitForm';
  self.Text := 'Form1';
  (self.dataGridView1 as System.ComponentModel.ISupportInitialize).EndInit();
  self.ResumeLayout(false);
end;
{$ENDREGION}

end.

Here is the Main.pas. I am trying to access dataGridView1 from Form1.pas (UnitForm).

namespace MonoPro;

interface

uses
  System.Drawing,
  System.Collections,
  System.Collections.Generic,
  System.Windows.Forms,
  System.ComponentModel,
  System.Threading,
  System.IO.Ports,
  MonoPro.*;

type
  /// <summary>
  /// Summary description for MainForm.
  /// </summary>
  MainForm = partial class(System.Windows.Forms.Form)
  private
    method SignalBtn_Click(sender: System.Object; e: System.EventArgs);
    method CommBtn_Click(sender: System.Object; e: System.EventArgs);
    method button1_Click(sender: System.Object; e: System.EventArgs);
    method button2_Click(sender: System.Object; e: System.EventArgs);
    method button4_Click(sender: System.Object; e: System.EventArgs);
    method button5_Click(sender: System.Object; e: System.EventArgs); 
    method ShutdownBtn_Click(sender: System.Object; e: System.EventArgs);
    method MySerialData(sender: System.Object; e:SerialDataReceivedEventArgs);
  protected
    method Dispose(disposing: Boolean); override;
  public
    RX:Array[0..5] of byte;
    TX:Array[0..6] of byte;
    serialPort1:System.IO.Ports.SerialPort;
    thr:Thread;
    stoploop:Boolean;
    mcommand:Byte;
    thechannel:Integer;
    fr : UnitForm;
    constructor;
    method FillTable;
    procedure mythread;
  end;

implementation

{$REGION Construction and Disposition}

constructor MainForm;
begin
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent();

  mcommand:=$AA;
  thechannel:=$01;
  stoploop:=false;
  thr:=nil;
  fr := new UnitForm;
  //
  // TODO: Add any constructor code after InitializeComponent call

  //
end;

method MainForm.Dispose(disposing: Boolean);
begin
  if disposing then begin
    //if assigned(components) then
    //  components.Dispose();

    //
    // TODO: Add custom disposition code here
    //

    SerialPort1.Close;
    stoploop:=true;
    thr.Abort;
  end;
  inherited Dispose(disposing);
end;
{$ENDREGION}

method MainForm.FillTable;
begin
    fr.dataGridView1;    //Here is my problem. With this line of code I am trying to see if the dataGridView1 belongs to fr winform.  
end;

method MainForm.MySerialData(sender: Object; e: SerialDataReceivedEventArgs);
begin
    if not SerialPort1.IsOpen then Exit;   

    try
        SerialPort1.Read(RX,0,5);
        FillTable;
    except on ex: exception do 
    begin
        exit;
    end;
    end;
end;

procedure MainForm.mythread;
begin
    while true do
    begin
        TX[0]:=$FF;
        TX[1]:=$01;
        TX[2]:=$01;
        TX[3]:=thechannel;
        TX[4]:=mcommand;
        TX[5]:=(TX[2] xor TX[3] xor TX[4]);

        SerialPort1.Write(TX,0,6);
        while SerialPort1.BytesToWrite>0 do;
        Thread.Sleep(100);

        if (stoploop) then
            break;
    end;
end;

method MainForm.CommBtn_Click(sender: System.Object; e: System.EventArgs);
begin

{$IFDEF CLR}
    if SerialPort1 = nil then
        SerialPort1 := new System.Io.Ports.SerialPort();
    SerialPort1.Close;

    SerialPort1 := new System.Io.Ports.SerialPort();
    SerialPort1.BaudRate:=19200;
    SerialPort1.DataBits:=8;
    SerialPort1.DtrEnable:=true;
    SerialPort1.Parity:=System.IO.Ports.Parity.Even;
    SerialPort1.PortName:='COM1';//'/dev/ttyS0';
    SerialPort1.ReadBufferSize:=4096;
    SerialPort1.ReadTimeout:=1000;
    SerialPort1.RtsEnable:=true;
    SerialPort1.StopBits:=System.IO.Ports.StopBits.One;
    SerialPort1.WriteTimeout:=1000;
    SerialPort1.DataReceived += new SerialDataReceivedEventHandler(MySerialData);
    SerialPort1.Open;

    thr:= new Thread(@mythread);
    thr.Start;
{$ENDIF}
end;

method MainForm.button1_Click(sender: System.Object; e: System.EventArgs);
begin
    thechannel:=$04;
    mcommand:=$A1;
end;

method MainForm.button2_Click(sender: System.Object; e: System.EventArgs);
begin
  thechannel:=$04;
  mcommand:=$A2;
end;

method MainForm.button4_Click(sender: System.Object; e: System.EventArgs);
begin
  thechannel:=$04;
  mcommand:=$A4;
end;

method MainForm.button5_Click(sender: System.Object; e: System.EventArgs);
begin
  thechannel:=$04;
  mcommand:=$A8;
end;

Any Idea?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:41:17+00:00Added an answer on May 23, 2026 at 6:41 pm

    In the properties of the DataGridView you can set its visibility to public.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGridView that displays data from a MS Access database. I'm using
I have a c# winform application (2008) with datagridview bound to data from sqlserver.
I have a datagridview where the users can select which subset of columns to
I have a DataGridView that I want to query using Linq (C# WinForm). I
How can I have a datagridview that will autogenerate a textbox instead of a
I have a DataGridView which has different rows and columns and it work perfectly
I have a DataGridView that has MultiSelect = true. After the user selects different
I have a DataGridView where the background of each row is different depending on
I want to bind columns in a DataGridView to pull values from two different
I have a DataGridView with unbound data that contains three different DataColumns . The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.