【解決方法】通貨マネージャーのポジションに関連付けられた行を非表示にすることはできません


私は DatagridView を持っています。
クラスからのデータソースを設定しました。

C#
taskerEntities te = new taskerEntities();
var OMsMasterDescriptiveIndicators = te.MyTable.Select(x => new lccls {Id = x.Id, name = x.name }).ToList();
MyGrid.DataSource = OMsMasterDescriptiveIndicators;

私のクラスは

C#
public class lccls
    {
        public string Id { get; set; }
        public Nullable<decimal> name { get; set; }
    }

特定のイベントで、現在の行を Visible = False にしたい。

C#
MyGrid.Rows[5].Visible = false;

しかし、私はこれを行うことができません。 その理由は、「datasource」が関連付けられているためだと思います。
ですから、私を助けてください。
どうすればこれを行うことができますか?
この問題についての私の考えは正しいですか?

エラーは

>   Row associated with the currency manager's position cannot be made<br />
> invisible

解決策 1

Google 検索で見つかりました これ[^] 答え。

バインディングを中断してからバインディングを再開する必要があるようです。 上記のリンクにある Web ページの例を採用しました。

CurrencyManager currencyManager1 = (CurrencyManager)BindingContext[MyGrid.DataSource];
currencyManager1.SuspendBinding();
MyGrid.Rows[5].Visible = false;
currencyManager1.ResumeBinding();

解決策 3

多分これは古いですが:
@A_グリフィン
はい、この方法の方が優れており、再度表示しても問題ありません(@Chase Viking)。

例:

C#
var item = dgv.Rows.Cast<DataGridViewRow>().FirstOrDefault(c => c.Cells[x].Value?.ToString() == X);
            if (item != null)
            {
                availableIpsDataGridView.CurrentCell = null;
                item.Visible = false;
            }

そしてそれを次のように表示します:

C#
var item = dgv.Rows.Cast<DataGridViewRow>().FirstOrDefault(c => c.Cells[x].Value?.ToString() == X);
                if (item != null)
                {
                    item.Visible = true;
                }

コメント

タイトルとURLをコピーしました