DataGridView.Rows.Count is 0

后端 未结 2 960
迷失自我
迷失自我 2021-01-28 16:03

I\'m trying to read the content of an excel file (I must process the data not show it) but the number of rows is 0. I did show the data in the UI and the rows didn\'t have a num

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-28 16:48

    try this:

    BindingSource bindingSource = new BindingSource();
    bindingSource.DataSource = resultDt;
    

    in your case:

    bindingSource.DataSource = ds.Tables[0];
    

    and:

    dgResult.DataSource = bindingSource;
    flowLayoutPanel.Controls.Add(dgResult); 
    
    var c = dgResult.Rows.Count;
    

    The binding source is what's responsible for syncing your data with the control. You want to use it, rather than trying to assign the table directly to the control.

    Reference:

    Datagridview rowcount showing 0 even when there is a valid datasource

提交回复
热议问题