回答編集履歴

1

見直しキャンペーン中

2023/07/27 14:23

投稿

TN8001
TN8001

スコア9326

test CHANGED
@@ -1,99 +1,48 @@
1
- Windows Formsの[DataGridView](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.forms.datagridview)と紛らわしいので、
2
-
3
- [DataGrid](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.controls.datagrid)と正しく表記してください。
4
-
5
-
6
-
7
-
1
+ Windows Formsの[DataGridView](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.forms.datagridview)と紛らわしいので、[DataGrid](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.controls.datagrid)と正しく表記してください。
8
2
 
9
3
  > チェックボックスをチェックされた時に、対象のファイル名(DataContextで取得できる?)を取得したいが、取得できない。
10
4
 
11
-
12
-
13
5
  1. `sender`を`CheckBox`にキャスト
14
-
15
6
  1. さらに`CheckBox`の`DataContext`を`orgFileInfo`にキャスト
16
-
17
-
18
7
 
19
8
  で取得できます。
20
9
 
21
10
 
22
-
23
-
24
-
25
- ```C#
11
+ ```cs
26
-
27
12
  using System.Collections.Generic;
28
-
29
13
  using System.Diagnostics;
30
-
31
14
  using System.Windows;
32
-
33
15
  using System.Windows.Controls;
34
16
 
35
-
36
-
37
17
  namespace Questions340821
38
-
39
18
  {
40
-
41
19
  public partial class MainWindow : Window
42
-
43
20
  {
44
-
45
21
  public MainWindow()
46
-
47
22
  {
48
-
49
23
  InitializeComponent();
50
24
 
51
-
52
-
53
25
  forder1DataGrid.ItemsSource = new List<orgFileInfo>
54
-
55
26
  {
56
-
57
27
  new orgFileInfo{ FileName = "FileName1", Comment = "Comment1", },
58
-
59
28
  new orgFileInfo{ FileName = "FileName2", Comment = "Comment2", },
60
-
61
29
  new orgFileInfo{ FileName = "FileName3", Comment = "Comment3", },
62
-
63
30
  };
64
-
65
31
  }
66
32
 
67
-
68
-
69
33
  private void folder1_click(object sender, RoutedEventArgs e)
70
-
71
34
  {
72
-
73
35
  if (sender is CheckBox checkBox)
74
-
75
36
  {
76
-
77
37
  if (checkBox.DataContext is orgFileInfo info)
78
-
79
38
  {
80
-
81
39
  Debug.WriteLine("IsChecked:" + info.IsChecked);
82
-
83
40
  Debug.WriteLine("FileName:" + info.FileName);
84
-
85
41
  Debug.WriteLine("Comment:" + info.Comment);
86
-
87
42
  Debug.WriteLine("");
88
-
89
43
  }
90
-
91
44
  }
92
-
93
45
  }
94
-
95
46
  }
96
-
97
47
  }
98
-
99
48
  ```