minimum rows to display in datagridview

Shaifali jain 420 Reputation points
2023-09-20T15:09:51.38+00:00

hello ,

is there a way by which i can set that there must be minimum number of rows is available to display in datagridview regardless of the data it has or not .

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

Accepted answer
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2023-09-21T13:23:49.37+00:00

    I looked at the now deleted reply and noticed you seem to want a master detail view. If that is the case see my code sample. Primary keys are shown for demo purposes only.

    masterDetails1

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2023-09-20T17:11:06.8833333+00:00

    If the DataGridView.DataSource is not set.

    if (dataGridView1.RowCount < 4)
    {
        dataGridView1.RowCount = 4;
    }
    

    Else if the DataSource is set than you need to decide what to do for instance if the DataSource is a DataTable, check the row count and dependent on rules for DataColumns decide how to add rows to the DataTable etc.

    0 comments No comments

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.