标签:cti 代码 end 绑定 索引 void items binding time()
WPF
XAML中:<ComboBox Name="_startTime" SelectionChanged="_startTime_SelectionChanged" Height="25" HorizontalAlignment="Left" />
在构造方法中:
_startTime.SelectedIndex = 6;//此处为从0开始的索引,用于时间下拉和列头的时间轴
SelectStartTime();DataGridBinDingTime();(注意代码顺序)
private void _startTime_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.RemovedItems.Count > 0)
{
//_gridGroup.Columns.Clear();//如果有需要打开注释,我就不再从试了
DataGridBinDingTime();
}
}
public void SelectStartTime()
{
List<string> hours = new List<string>();
for (int i = 1; i <= 24; i++)
{
hours.Add(i + ":00");
}
_startTime.ItemsSource = hours;
}
public void DataGridBinDingTime()
{
List<string> times = new List<string>();
string time = _startTime.SelectedValue.ToString();
string[] arr = time.Split(‘:‘);
string splittime = arr[0];
for (int i = Convert.ToInt32(splittime); i <= 24; i++)
{
times.Add(i.ToString() + ":00");
}
for (int i = 0; i < times.Count; i++)
{
DataGridTextColumn dl = new DataGridTextColumn();
dl.Header = times[i];
_gridGroup.Columns.Add(dl);
}
}
_gridGroup:是DataGrid的Name
标签:cti 代码 end 绑定 索引 void items binding time()
原文地址:https://www.cnblogs.com/AnYiJianMo/p/14850763.html