zoukankan      html  css  js  c++  java
  • wpf datagrid 如何自定义行的控件实例,(textbox 并选中则全选)

    主要是为了用户输入方便

    按回车,选中下一列,text自动获取焦点,输入状态

    获取控件实例  https://blog.csdn.net/m15188153014/article/details/48627757 

    textbox选中则全选  https://www.cnblogs.com/babietongtianta/p/3952214.html 

            private void dgContent_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                DataGridTemplateColumn tempColumn = this.dgContent.Columns[4] as DataGridTemplateColumn;
                FrameworkElement element = this.dgContent.Columns[4].GetCellContent(this.dgContent.SelectedItem);
                if (element != null)
                {
                    //把单元格元素转换为相应的控件,再从该控件中取值
                    TextBox ck = tempColumn.CellTemplate.FindName("tb", element) as TextBox;
                    if (ck != null)
                    {
                        //if(ck.MouseDoubleClick!=null)
                        ck.PreviewMouseDown += new MouseButtonEventHandler(LIKE_textBox_PreviewMouseDown);//注意,这个事件的注册必须在LIKE_textBox获得焦点之前
                        ck.GotFocus += new RoutedEventHandler(LIKE_textBox_GotFocus);
                        ck.LostFocus += new RoutedEventHandler(LIKE_textBox_LostFocus);
                        ck.Focus();
                        ck.PreviewMouseDown -= new MouseButtonEventHandler(LIKE_textBox_PreviewMouseDown);//注意,这个事件的注册必须在LIKE_textBox获得焦点之前
                        ck.GotFocus -= new RoutedEventHandler(LIKE_textBox_GotFocus);
                        ck.LostFocus -= new RoutedEventHandler(LIKE_textBox_LostFocus);
    
                    }  
                }
            }
    
            void LIKE_textBox_LostFocus(object sender, RoutedEventArgs e)
            {
                (sender as TextBox).PreviewMouseDown += new MouseButtonEventHandler(LIKE_textBox_PreviewMouseDown);
            }
    
            void LIKE_textBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
            {
                (sender as TextBox).Focus();
                e.Handled = true;
            }
    
            void LIKE_textBox_GotFocus(object sender, RoutedEventArgs e)
            {
                (sender as TextBox).SelectAll();
                (sender as TextBox).PreviewMouseDown -= new MouseButtonEventHandler(LIKE_textBox_PreviewMouseDown);
            }
  • 相关阅读:
    CXX解析CSV文件
    linux通过cifs挂载windows共享目录
    oracle生产环境存储过程调试方案
    imp导入库表空间找不到问题记录
    银行怎么盘头寸
    jQuery插件之【jqGrid】常用语法整理-【更新】
    Jquery一些笔记
    request对象的五个集合
    jQuery插件之【jqGrid】常用语法整理-【更新】
    MVC中几种常用ActionResult
  • 原文地址:https://www.cnblogs.com/swobble/p/9871627.html
Copyright © 2011-2022 走看看