作者GooLoo (平凡)
看板C_Sharp
標題wpf datagrid問題
時間Wed Nov 7 08:56:47 2018
我可以對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://webptt.com/m.aspx?n=bbs/C_Sharp/M.1541552210.A.46D.html
1F:→ testPtt: foreach(var cell in DataGrid.SelectedCells) 11/07 11:53
2F:→ testPtt: 不建議用程式控制ui寫入資料 我實做只會直接寫入不經過ui 11/08 14:13
3F:→ testPtt: 網路上可能能找到index取得指定cell的方法 11/08 14:15
4F:→ testPtt: 你在取得cell還要.DataContext再轉型才寫入 11/08 14:18
不懂你的意思耶,有範例嗎? DataContext轉型和直接寫入的範例
網路看到都item整列寫入,而我想修改其中一個cell的值而已
5F:→ testPtt: 直接修改data內容 或是找到cell.DataContext 11/08 21:14
6F:→ testPtt: 我從沒做過ui從index去找 最後都要取出item對應的屬性 11/08 21:58
7F:→ testPtt: 程式碼可能像(cell.item as (type)).屬性=要填的值; 11/08 22:02
8F:→ testPtt: 屬性大概就你的col1,col2... 11/08 22:07
網上都是教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
9F:→ testPtt: 如果你是單純數值方陣 那可能不適合DataGrid做 11/08 23:14
10F:→ testPtt: 你也可以在selected的同時去更新numericupdown的binding 11/08 23:18
對,單純數值矩陣,因為之前datagridview有成功,轉wpf失敗,如果不適合,該用哪一個呢?
※ 編輯: GooLoo (1.171.26.119), 11/08/2018 23:35:44
11F:→ testPtt: 內建只有DataGrid可以 遇到這種需求我傾向寫usercontrol 11/08 23:44
12F:→ GooLoo: 瞭解,感謝喔 11/09 12:31