リストとアイテムソースを使用して動的にデータグリッドに行を追加しています。WPFで動的に追加するときの編集を無効にする
しかし、データグリッドの一部のセルを編集するためにユーザーを無効にしたいとします。
私は簡単な方法でこれを行うことができますか?
添付私のコード:あなたがしたい場合
/// <summary>
/// this class contain the data for the table in order to add the data for the table
/// </summary>
public class DataFroGrid
{
private string des;
/// <summary>
/// conatin the desction field for the data
/// </summary>
public string Description
{
get { return des; }
set { des = value; }
}
private string numberOfBytes;
/// <summary>
/// contain the number of byte for adding to the data
/// </summary>
public string NumberOfBytes
{
get { return numberOfBytes; }
set { numberOfBytes = value; }
}
private string value;
/// <summary>
/// contain the value for adding to the data
/// </summary>
public string Value
{
get { return this.value; }
set { this.value = value; }
}
public DataFroGrid()
{
des = "";
numberOfBytes = "";
value = "";
}
}
private List<DataFroGrid> _ListForDataCommands; // a list for attached the data as a data source
public addQuestionMarkCommand(string[] description, int[] numberOfBytes ,string [] Value)
{
WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; // start window in the middle of the screen
_ListForDataCommands = new List<DataFroGrid>();
res = ""; // get the result values
InitializeComponent();
eUserClosed += addQuestionMarkCommand_eUserClosed; // create an event for closing the window.
// update the item source per the data that has been received
for (int i = 0; i < description.Length; i++)
{
DataFroGrid dfg = new DataFroGrid();
dfg.Description = description[i];
dfg.NumberOfBytes = numberOfBytes[i].ToString();
dfg.Value = Value[i];
_ListForDataCommands.Add(dfg);
//want to disable editing cell per data????
}
dataGridCommand.ItemsSource = _ListForDataCommands;
}
あなたのXAMLを見ることが有用であろう。これをチェックして他のアイデアを投稿してください:http://stackoverflow.com/questions/3843331/how-to-make-wpf-datagridcell-readonly – Taterhead