gpt4 book ai didi

c# - Datagrid 我无法刷新字段

转载 作者:太空宇宙 更新时间:2023-11-03 10:33:44 25 4
gpt4 key购买 nike

我无法刷新数据网格中的字段。

这是我的DataGrid:

<DataGrid ItemsSource="{Binding Dati_Viaggio}"
SelectedItem="{Binding SelectDati_Viaggio}"
Style="{DynamicResource ST_DataGrid}"
CellStyle="{DynamicResource St_DataGridCellStyle}"
SelectionMode="Single" Name="Dg_Dati" IsReadOnly="True"
RowDetailsVisibilityMode="VisibleWhenSelected">

这是我要刷新的 DataGrid 中的字段

<DataGridTextColumn x:Name="col_NumOrd" Binding="{Binding Path=NumOrd}"
Header="Num. Ord." Width="150"/>

这是属性:

public ObservableCollection<Model_Ricerca_Dati_Viaggio> Dati_Viaggio { get; set; }
private Model_Ricerca_Dati_Viaggio _SelectDati_Viaggio;
public Model_Ricerca_Dati_Viaggio SelectDati_Viaggio
{
get { return _SelectDati_Viaggio; }
set
{
_SelectDati_Viaggio = value;
OnPropertyChanged("SelectDati_Viaggio");
}
}

为什么如果我编写这段代码,DataGrid 不会刷新该字段?

SelectDati_Viaggio.NumOrd= "abcabc";
OnPropertyChanged("SelectDati_Viaggio");

谢谢。

最佳答案

尝试通过重新声明和重新查询集合来刷新绑定(bind)并初始化到数据网格,在搜索了几天的解决方案后尝试了这个。如果你明白了。

server = mongoClient.GetServer();
database = server.GetDatabase("facultyDataAndSchedule");
collection = database.GetCollection<facultyData>("faculty");
var query = collection.FindAllAs<facultyData>()
.SetFields(Fields.Include("facultyID", "term", "acadYear", "age",
"program", "lastName", "firstName", "middleName", "dateOfBirth",
"rank", "yearsOfTeachingS", "yearsOfTeachingO", "status", "services"));
// List<facultyData> resultList = query.ToList<facultyData>();
resultBinding = new ObservableCollection<facultyData>(query);
facultyDataGrid.ItemsSource = resultBinding;
try
{
try
{
var entity = new facultyData
{
facultyID = facultyID_Textbox.Text.ToString(),
term = termComboBox.SelectedItem.ToString(),
age = int.Parse(age_TextBox.Text),
acadYear = "2014-2015",
firstName = firstName_TextBox.Text.ToString(),
lastName = lastName_TextBox.Text.ToString(),
middleName = middleName_TextBox.Text.ToString(),
dateOfBirth = dateOfBirth_TextBox.Text.ToString(),
program = "progra",
rank = "gegs",
services = "gegsg",
status = "geh",
yearsOfTeachingO = 1,
yearsOfTeachingS = 1
};
collection.Insert(entity);
}
catch (FormatException ex)
{
Console.WriteLine(ex);
}
}
catch (MongoConnectionException ex)
{
Console.WriteLine(ex);
}
var query1 = collection.FindAllAs<facultyData>()
.SetFields(Fields.Include("facultyID", "term", "acadYear", "age",
"program", "lastName", "firstName", "middleName", "dateOfBirth",
"rank", "yearsOfTeachingS", "yearsOfTeachingO", "status", "services"));
// List<facultyData> resultList = query.ToList<facultyData>();
resultBinding = new ObservableCollection<facultyData>(query1);
facultyDataGrid.ItemsSource = resultBinding;

关于c# - Datagrid 我无法刷新字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28739678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com