Unable to see rows and column in datagridview

rahul kumar 605 Reputation points
2023-06-30T07:34:07.9433333+00:00

Hi , I have created a custom datagridview but it is not showing any rows and columns only headers . the declaration part is below .

  public partial class Paymentdatagridview : DataGridView
    {
        
       
        public Paymentdatagridview()
        {
            // Add the columns to your custom DataGridView
            DataGridViewColumn column1 = new DataGridViewTextBoxColumn();
            column1.Name = "Column1";
            column1.HeaderText = "Particulars";
            column1.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            column1.SortMode = DataGridViewColumnSortMode.Automatic;
            this.Columns.Add(column1);

            DataGridViewColumn column2 = new DataGridViewTextBoxColumn();
            column2.Name = "Column2";
            column2.HeaderText = "Amount";
            column2.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            column2.SortMode = DataGridViewColumnSortMode.Programmatic;
            this.Columns.Add(column2);
            
            this.ColumnHeadersDefaultCellStyle.Font = new Font("Tahoma", 9.75F, FontStyle.Bold);
            this.CellBorderStyle = DataGridViewCellBorderStyle.None;          
            InitializeComponent();
        }

       

        protected override void OnEnter(EventArgs e)
        {
            // Set the current cell to the first cell and enable editing when the control receives focus
            if (RowCount > 0 && ColumnCount > 0)
            {
                CurrentCell = Rows[0].Cells[0];
                BeginEdit(true);
            }

            base.OnEnter(e);
        }

the inheriting form's code behind

 private void paymentreceiptchild_Load(object sender, EventArgs e)
        {
            
            paymentdatagridview1.Focus();
         

        }


User's image

as you can see that after starting , i cannot see any row inside it .

Developer technologies Windows Forms
Developer technologies C#
{count} votes

Accepted answer
  1. Anonymous
    2023-06-30T08:17:54.19+00:00

    Hi @rahul kumar , Welcome to Microsoft Q&A.

    You set AllowUserToAddRows to false;

    Try using the code this.AllowUserToAddRows = true;

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.