teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

見直しキャンペーン中

2023/07/27 14:23

投稿

TN8001
TN8001

スコア10111

answer CHANGED
@@ -1,50 +1,48 @@
1
- Windows Formsの[DataGridView](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.forms.datagridview)と紛らわしいので、
2
- [DataGrid](https://docs.microsoft.com/ja-jp/dotnet/api/system.windows.controls.datagrid)と正しく表記してください。
3
-
4
-
5
- > チェックボックスチェックされた時、対象のファイル名(DataContextで取得できる?)を取得したいが、取得できない。
6
-
7
- 1. `sender`を`CheckBox`にキャスト
8
- 1. さらに`CheckBox`の`DataContext`を`orgFileInfo`にキャスト
9
-
10
- で取得できます。
11
-
12
-
13
- ```C#
14
- using System.Collections.Generic;
15
- using System.Diagnostics;
16
- using System.Windows;
17
- using System.Windows.Controls;
18
-
19
- namespace Questions340821
20
- {
21
- public partial class MainWindow : Window
22
- {
23
- public MainWindow()
24
- {
25
- InitializeComponent();
26
-
27
- forder1DataGrid.ItemsSource = new List<orgFileInfo>
28
- {
29
- new orgFileInfo{ FileName = "FileName1", Comment = "Comment1", },
30
- new orgFileInfo{ FileName = "FileName2", Comment = "Comment2", },
31
- new orgFileInfo{ FileName = "FileName3", Comment = "Comment3", },
32
- };
33
- }
34
-
35
- private void folder1_click(object sender, RoutedEventArgs e)
36
- {
37
- if (sender is CheckBox checkBox)
38
- {
39
- if (checkBox.DataContext is orgFileInfo info)
40
- {
41
- Debug.WriteLine("IsChecked:" + info.IsChecked);
42
- Debug.WriteLine("FileName:" + info.FileName);
43
- Debug.WriteLine("Comment:" + info.Comment);
44
- Debug.WriteLine("");
45
- }
46
- }
47
- }
48
- }
49
- }
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)と正しく表記してください。
2
+
3
+ > チェックボックスをチェックされた時に、対象のファイル名(DataContextで取得できる?)を取得したいが、取得できない。
4
+
5
+ 1. `sender``CheckBox`キャスト
6
+ 1. さらに`CheckBox`の`DataContext`を`orgFileInfo`にキャスト
7
+
8
+ で取得できます。
9
+
10
+
11
+ ```cs
12
+ using System.Collections.Generic;
13
+ using System.Diagnostics;
14
+ using System.Windows;
15
+ using System.Windows.Controls;
16
+
17
+ namespace Questions340821
18
+ {
19
+ public partial class MainWindow : Window
20
+ {
21
+ public MainWindow()
22
+ {
23
+ InitializeComponent();
24
+
25
+ forder1DataGrid.ItemsSource = new List<orgFileInfo>
26
+ {
27
+ new orgFileInfo{ FileName = "FileName1", Comment = "Comment1", },
28
+ new orgFileInfo{ FileName = "FileName2", Comment = "Comment2", },
29
+ new orgFileInfo{ FileName = "FileName3", Comment = "Comment3", },
30
+ };
31
+ }
32
+
33
+ private void folder1_click(object sender, RoutedEventArgs e)
34
+ {
35
+ if (sender is CheckBox checkBox)
36
+ {
37
+ if (checkBox.DataContext is orgFileInfo info)
38
+ {
39
+ Debug.WriteLine("IsChecked:" + info.IsChecked);
40
+ Debug.WriteLine("FileName:" + info.FileName);
41
+ Debug.WriteLine("Comment:" + info.Comment);
42
+ Debug.WriteLine("");
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
50
48
  ```