シンプルなこちら。行のセットを持つデータグリッドを作成しました。行がロードされた後、特定のロジックに基づいて特定の行を非表示にしたいですか?
何か案は?
シンプルなこちら。行のセットを持つデータグリッドを作成しました。行がロードされた後、特定のロジックに基づいて特定の行を非表示にしたいですか?
何か案は?
行ロード イベント、つまり LoadingRow では、行のロードごとに、データ コンテキストがある DataGridRow を取得します。Person(ID、名前)としましょう
これがあなたが遊ぶことができる方法です..
private void dataGrid1_LoadingRow(object sender, DataGridRowEventArgs e)
{
if(e.Row != null)
{
var row = e.Row.DataContext;
var person = row as Person;
if (person != null && person.Id == 2)
{
(e.Row as DataGridRow).IsEnabled = false;
}
if (person != null && person.Id == 1)
{
(e.Row as DataGridRow).Visibility = Visibility.Collapsed;
}
}
}
コードを微調整する必要がありますが、これに対する解決策を探していたので、投稿する価値があると思いました。
Private Sub gridComments_LoadingRow(sender As Object, e As DataGridRowEventArgs) Handles gridComments.LoadingRow
Dim row As DataGridRow = e.Row
For Each col As DataGridColumn In gridComments.Columns
Dim g1 As FrameworkElement = col.GetCellContent(e.Row)
Dim c As UIElement = g1.FindName("ChildElementName")
c.Opacity = 0 'Change the desired properties here
Next
End Sub
private void gridComments_LoadingRow(object sender, DataGridRowEventArgs e)
{
DataGridRow row = e.Row;
foreach (DataGridColumn col in gridComments.Columns) {
FrameworkElement g1 = col.GetCellContent(e.Row);
UIElement c = g1.FindName("ChildElementName");
c.Opacity = 0;
//Change the desired properties here
}
}
少し遅れましたが、これは私にとってはうまくいきました。