首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > CAD教程 >

datagrid 数据修改解决方法

2012-12-30 
datagrid 数据修改通过datagrid的一列中的下拉列表,来确定datagrid另一列中的数据数据源数据类型代码:publ

datagrid 数据修改
通过datagrid的一列中的下拉列表,来确定datagrid另一列中的数据
数据源数据类型代码:


public class Phase : INotifyPropertyChanged {
        private int _Code;
        public int PhaseID { get; set; }
        public int YellowFlashTime { get; set; }
        public int GreenFlashTime { get; set; }
        public int ShortestTime { get; set; }
        public int LongestTime { get; set; }
        public ObservableCollection<int> PhaseCode { get; set; }
        public int Code {
            get {
                return _Code;
            }
            set {
                _Code = value;
                NotifyPropertyChanged("Code");
            }
        }

        public Phase(int _PhaseID, int _YellowFlashTime, int _GreenFlashTime, int _ShortestTime, int _LongestTime) {
            PhaseID = _PhaseID;
            YellowFlashTime = _YellowFlashTime;
            GreenFlashTime = _GreenFlashTime;
            ShortestTime = _ShortestTime;
            LongestTime = _LongestTime;
            PhaseCode = new ObservableCollection<int>();
        }
        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string info) {
            if (PropertyChanged != null) {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
    }

下拉列表代码:

<dg:DataGridTemplateColumn Header="方向" Width="40">
                            <dg:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>


                                    <source:MyComboBox x:Name="OrientationSelect" 
                                          SelectedItem="{Binding Path=方向,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
                                          ItemsSource="{Binding Source={StaticResource Orientation}}"
                                          IsReadOnly="False"
                                          DisplayMemberPath="Day" SelectedValuePath="Index"
                                          SelectionChanged="CrossingName_SourceUpdated" />
                                </DataTemplate>
                            </dg:DataGridTemplateColumn.CellTemplate>
                        </dg:DataGridTemplateColumn>


改变列的代码:

<source:CustomColumn Header="相位代码" Width="70" x:Name="Code"
                            Binding="{Binding Code, Mode=TwoWay}">
                        </source:CustomColumn>

在下拉列表中的选择事件代码:

private void CrossingName_SourceUpdated(object sender, SelectionChangedEventArgs e) {
            int index = Convert.ToInt32(((ComboBox)sender).SelectedValue)-1;
            OrientationIndex = index;
            CrossNameIndex = CrossingName.SelectedIndex;
            var item = CrossingName.SelectedItem as Phase;
            
            if (item != null) {
                //MessageBox.Show(PhaseCode.GetType().ToString());


                CustomColumn customColumn = new CustomColumn();
                try {
                    //customColumn = new CustomColumn();
                } catch (TypeInitializationException ex) {
                    Console.WriteLine(ex.ToString());
                }
                //改变数据源的数据
                _DayPeriodList[DayPeriodIndex][PhasePeriodIndex].PhaseList[CrossingName.SelectedIndex].Code =
                    _DayPeriodList[DayPeriodIndex][PhasePeriodIndex].PhaseList[CrossingName.SelectedIndex].PhaseCode[index];                //customColumn.PhaseCode = Convert.ToString( _DayPeriodList[DayPeriodIndex][PhasePeriodIndex].PhaseList[CrossingName.SelectedIndex].PhaseCode[index]);
                //CrossingName.ItemsSource = null;
                //CrossingName.ItemsSource = _DayPeriodList[DayPeriodIndex][PhasePeriodIndex].PhaseList;
            }     
        }



求各位大侠能给个修改datagrid一个单元格数据的方法,在线等啊。。。。
[解决办法]
datagrid1.CurrentCell

热点排行