c# dataGridView 光标选中文字,点别的按钮,如何让选中文字不变,而不是自动选中整行,SelectionMode里也没有按光标选中文字的选项,不知道怎么办. 
比如有 3行文字.
第一行是:  aaa bbb ccc ddd
第二行是:  eee fff ggg hhh
第三行是:  iii jjj kkk lll
例如:我选中了 fff, 然后我再点form上的一个按钮,比如那个按钮是复制功能, 问题来了,点了复制按钮, 本来fff是选中状态,
这下就突然变成 第二行整行是选中状态了,即 eee fff ggg hhh处于选中状态了. 虽然fff可以被复制到剪切板, 但给人的感觉不好, 用户肯定还希望 fff是只被选中的文字. 这改怎么做呀?

解决方案 »

  1.   

    dataGridView 默认就是选中单元格的 
      

  2.   

    //
            // 摘要:
            //     取消选择当前选定的所有单元格(所指示的单元格除外),可以选择确保所指示的单元格处于选定状态。
            //
            // 参数:
            //   columnIndexException:
            //     要排除的列索引。
            //
            //   rowIndexException:
            //     要排除的行索引。
            //
            //   selectExceptionElement:
            //     如果要选择已排除的单元格、行或列,为 true;如果要保留它的初始状态,则为 false。
            //
            // 异常:
            //   System.ArgumentOutOfRangeException:
            //     columnIndexException 大于最大的列索引。- 或 - 如果 System.Windows.Forms.DataGridView.SelectionMode
            //     为 System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect,则 columnIndexException
            //     小于 -1;否则 columnIndexException 小于 0。- 或 - rowIndexException 大于最大的行索引。- 或 -
            //     如果 System.Windows.Forms.DataGridView.SelectionMode 为 System.Windows.Forms.DataGridViewSelectionMode.FullColumnSelect,则
            //     rowIndexException 小于 -1;否则 rowIndexException 小于 0。
            protected void ClearSelection(int columnIndexException, int rowIndexException, bool selectExceptionElement);
    可能需要在 离开方法里调用这个方法,但这个方法是protected方法,怎么能调用呢
      

  3.   


                DataGridViewCell cell = dataGridView1.CurrentCell;
                cell.Selected = true;
      

  4.   

    点到这个控件,属性里面有找到这个RowHeaderSBorderStylr把他设置成Raised就可以了
      

  5.   

    我只想 让 fff 那几个字获得焦点, 而不是 包含那几个字的整个单元格获得焦点. 
      

  6.   

    好像外国网站也解决不了这个问题.
    The DataGridView is a powerful grid control included in the .NET Framework.  One function missing, however, is the ability to hide the current selection when the DataGridView control is not focused.  What the DataGridView class needs is a HideSelection property, similar to the ListView and TextBox.  But the .NET designers have not included this capability in the DataGridView class.