wpf datagrid問題

看板C_Sharp作者 (平凡)時間5年前 (2018/11/07 08:56), 5年前編輯推噓0(0012)
留言12則, 2人參與, 5年前最新討論串1/1
我可以對datagrid的cell寫入data 我datagrid已經blind 100*100 data 我的Column Header命名是Col1到Col100 問題1:我想修改某cell值, item[0].Col0=10, item[0].Col1=20,..... 我如何用for幫我對某些局部row, col修改 For (int i=0;i<50;i++) For(int j=0;j<50;j++) item[i]. j=10; 因Col1到Col100是一個.......屬性, j是index,是一個int, 無法帶 我看過網頁教學和文件,都是用col1一個一個加 有人知道怎麼做嗎? 問題2:winform時可以Datagrid1. Columns[i]. Rows[j]. isSelected==true) 所以cell依序判isselected Wpf我試過,找不到isselected 有人知道在wpf怎麼依序判cell是不是isselected呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.72.44.101 ※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1541552210.A.46D.html

11/07 11:53, 5年前 , 1F
foreach(var cell in DataGrid.SelectedCells)
11/07 11:53, 1F

11/08 14:13, 5年前 , 2F
不建議用程式控制ui寫入資料 我實做只會直接寫入不經過ui
11/08 14:13, 2F

11/08 14:15, 5年前 , 3F
網路上可能能找到index取得指定cell的方法
11/08 14:15, 3F

11/08 14:18, 5年前 , 4F
你在取得cell還要.DataContext再轉型才寫入
11/08 14:18, 4F
不懂你的意思耶,有範例嗎? DataContext轉型和直接寫入的範例 網路看到都item整列寫入,而我想修改其中一個cell的值而已

11/08 21:14, 5年前 , 5F
直接修改data內容 或是找到cell.DataContext
11/08 21:14, 5F

11/08 21:58, 5年前 , 6F
我從沒做過ui從index去找 最後都要取出item對應的屬性
11/08 21:58, 6F

11/08 22:02, 5年前 , 7F
程式碼可能像(cell.item as (type)).屬性=要填的值;
11/08 22:02, 7F

11/08 22:07, 5年前 , 8F
屬性大概就你的col1,col2...
11/08 22:07, 8F
網上都是教GD1. Col1="10" ,這個我會。但我想做numericupdown去更新我 selected cell,現在已經可以得到selected cell index, 只差cell 不可以用index修 改, c#的datgridview可以culumns[i].Rows[j],WPF不行! selected cell index是數字, Col1是屬性, 無法帶入 ※ 編輯: GooLoo (1.171.26.119), 11/08/2018 23:10:57

11/08 23:14, 5年前 , 9F
如果你是單純數值方陣 那可能不適合DataGrid做
11/08 23:14, 9F

11/08 23:18, 5年前 , 10F
你也可以在selected的同時去更新numericupdown的binding
11/08 23:18, 10F
對,單純數值矩陣,因為之前datagridview有成功,轉wpf失敗,如果不適合,該用哪一個呢? ※ 編輯: GooLoo (1.171.26.119), 11/08/2018 23:35:44

11/08 23:44, 5年前 , 11F
內建只有DataGrid可以 遇到這種需求我傾向寫usercontrol
11/08 23:44, 11F

11/09 12:31, 5年前 , 12F
瞭解,感謝喔
11/09 12:31, 12F
文章代碼(AID): #1RuZXIHj (C_Sharp)