Unable To set row visible false of a datagridview

后端 未结 6 1585
北荒
北荒 2020-11-27 05:55

I have a DataGridView where I set DataSource:

taskerEntities te = new taskerEntities();
var OMsMasterDescriptiveIndicators = te.MyT         


        
相关标签:
6条回答
  • 2020-11-27 06:45

    I have an example for U. I have a datagridview that may multiselected row. When i click the button to visible false row that selected. Try this:

    foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                CurrencyManager currencyManager1 =(CurrencyManager)BindingContext[dataGridView1.DataSource];
                    currencyManager1.SuspendBinding();
                    dataGridView1.CurrentCell = null;
                    row.Visible = false;
            }
            dataGridView1.Refresh();
    

    Remember to set property SelectionMode: FullRowSelect

    0 讨论(0)
  • 2020-11-27 06:48

    I know this is an old topic, but an alternative solution (my code is vb.net, but I assume it would translate)

    If WO_DGV.CurrentCell.RowIndex = i Then
      'you cannot make invisible the row that is 'current'
      WO_DGV.CurrentCell = WO_DGV.Rows(i - 1).Cells("act") 
      'to get to this code I know that there is a row before i, which is why I can use i-1 as new focus
    End If
    WO_DGV.Rows(i).Visible = False 
    
    0 讨论(0)
  • 2020-11-27 06:55

    Maybe a little late to answer this topic but I suggest you to use DataTable.DefaultView.RowFilter property to filter what you need to show on the bounded DataGridView. Please check the following link for more informtion: https://docs.microsoft.com/en-us/dotnet/api/system.data.dataview.rowfilter?redirectedfrom=MSDN&view=netframework-4.8#System_Data_DataView_RowFilter

    regards.

    0 讨论(0)
  • 2020-11-27 06:59

    After searching a lot, I got the solution

    CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[MyGrid.DataSource];  
    currencyManager1.SuspendBinding();
    MyGrid.Rows[5].Visible = false;
    currencyManager1.ResumeBinding();
    
    0 讨论(0)
  • 2020-11-27 07:01

    Cannot set yourDataGridView row visible property to false when current row index Will encounter such error if trying to hide current cell

    soulution :

    when yourDataGridView Data source is not null :

      CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[yourDataGridView.DataSource];
                           currencyManager1.SuspendBinding();
                           yourDataGridView.Rows[Target Index].Visible = false;
                           currencyManager1.ResumeBinding();
    

    when yourDataGridView Data source is null :

     yourDataGridView.CurrentCell = null;
     yourDataGridView.Rows[Target Index].Visible = false;
    
    0 讨论(0)
  • 2020-11-27 07:01

    Example

            foreach (DataGridViewRow rw in dataGridView1.Rows)
            {
    
            if (rw.Cells[14].Value.ToString() == "") // this Cell have a TEXT, 
                {
                    CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[dataGridView1.DataSource];
                    currencyManager1.SuspendBinding();
                    rw.Visible = false; 
                    currencyManager1.ResumeBinding();
    
                }
            }
    

    this show only the row that have in the cell index 14, if this is blank or empty the whole row not show

    0 讨论(0)
提交回复
热议问题