编辑时,Datagridview单元格背景变为黑色 [英] Datagridview cell backcolor becomes black when editing

查看:437
本文介绍了编辑时,Datagridview单元格背景变为黑色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。

我有一个datagridview,它有许多datagridviewtextbox列。当我开始编辑单元格时,其背面颜色变为黑色,文本框中的任何内容都不可见,因为其背面颜色会发生变化。我已将当前单元格的背景颜色设置为白色,但它从不改变颜色。我的代码是



 sales_dataGridView.CurrentCell.Style.ForeColor = Color.Black; 
sales_dataGridView.CurrentCell.Style.BackColor = Color.White;





如何解决这个问题?

解决方案

在CellContentClick事件上附加处理程序并实现此目的:



  void  dataGridView_EditingControlShowing( object  sender,DataGridViewEditingControlShowingEventArgs e)
{
e.CellStyle.BackColor = Color。白色;
}





最好的问候!


将此代码粘贴在列标签的正上方来源。



<前lang =HTML> < SelectedRowStyle BackColor = #9FCACA ForeColor < span class =code-keyword> = 黑色 / >





i hope这对你有帮助。





yogesh。


你好,



似乎你的代码一切正常,当我使用它时它完全应该做的事情,

但你必须检查sales_data DefaultCellStyle的GridView属性尝试:



 sales_dataGridView1.DefaultCellStyle.BackColor = Color.White; 
sales_sales_dataGridView1.DefaultCellStyle.ForeColor = Color.Black;
sales_dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Red;
sales_dataGridView1.DefaultCellStyle.SelectionForeColor = Color.white;





此代码应在程序中输入,

来自它对整个程序的影响,在我的情况下



 命名空间 Test_app 
{
/// < 摘要 >
< span class =code-summarycomment> /// MainForm的描述。
/// < / summary >
public partial class MainForm:Form
{
public MainForm()
{
//
// InitializeComponent()调用
//
//
InitializeComponent();

//
// TODO:在InitializeComponent()调用后添加构造函数代码。
//
dataGridView1.DefaultCellStyle.BackColor = Color.White;
dataGridView1.DefaultCellStyle.ForeColor = Color.Black;
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Red;
dataGridView1.DefaultCellStyle.SelectionForeColor = Color.White;
dataGridView1.Refresh();
}

void Button1Click( object sender,EventArgs e)

// 程序的其余部分







插入四行代码后,如果整个程序中没有任何一点你没有改变,





sales_dataGridView1.DefaultCellStyle.BackColor

sales_sales_dataGridView1.DefaultCellStyle.ForeColor

sales_dataGridView1.DefaultCellStyle .SelectionBackColor

sales_dataGridView1.DefaultCellStyle.SelectionForeColor



sales_dataGridView1.CellStyle.BackColor

sales_sales_dataGridView1.CellStyle.ForeColor

sales_dataGridView1.CellStyle.SelectionBackColor

sales_dataGridView1.CellStyle.SelectionForeColor





结果应该是:

单元格选择单元格后点击它是红色的,

单元格后的颜色用它来编辑内容,通过双击它或按Enter键是白色的,

文本颜色总是黑色,未选中的单元格的颜色是白色。



如果仍然出现问题,当您输入单元格以修改内容时,DataGridView背景颜色与文本颜色匹配,那么您应该检查程序中的所有位置,以便最终插入更改颜色的代码。

如果程序是在Visual Tool中制作的,只需将ToolGridView中的DataGridView插入到Mainform上,

检查属性DataGridView DefaultCellStyle,并检查EditColumns对话框中的属性DataGridView DefaultCellStyle。有时这两个不同选项中的颜色设置与程序代码中的设置不同,如果在某处使用Reset命令或Refresh命令,则可以覆盖程序代码的simetimes。程序。

另外,settin的区别DataGridView DefaultCellStyle的属性中的gs颜色,以及EditColumns中的属性DataGridView DefaultCellStyle的对话框通常会导致程序中出现未解决的错误,

您没有看到(程序运行显然是正常的,但它有错误)。

这适用于DataGredView控件的这两个属性中的所有设置。



一切顺利,

Peric Zeljko

periczeljkosmederevo @ y ahoo.com


Hi.
I have a datagridview that has a number of datagridviewtextbox columns. When i start editing a cell its back color becomes black and nothing in the textbox is visible as its back color changes. I have set the backcolor of the current cell to white but it never changes the color. My code is

sales_dataGridView.CurrentCell.Style.ForeColor = Color.Black;
sales_dataGridView.CurrentCell.Style.BackColor = Color.White;



How can i solve this problem?

解决方案

Attach handler on CellContentClick event and implenent this:

void dataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
       {
           e.CellStyle.BackColor = Color.White;
       }



Best Regards!


Paste this code just above the column tag in source.

<SelectedRowStyle BackColor="#9FCACA" ForeColor="Black" />



i hope this will help you.


yogesh.


Hello,

It seems that everything is ok with your code,when I use it it do exactly what it should do ,
but you have to check sales_dataGridView properties for DefaultCellStyle try:

sales_dataGridView1.DefaultCellStyle.BackColor = Color.White;
sales_sales_dataGridView1.DefaultCellStyle.ForeColor = Color.Black;
sales_dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Red;
sales_dataGridView1.DefaultCellStyle.SelectionForeColor = Color.white;



This code should be typed in the program,
from where it has an influence on the whole program, in my case

namespace Test_app
{
  /// <summary>
  /// Description of MainForm.
  /// </summary>
  public partial class MainForm : Form
  {
    public MainForm()
    {
	//
	// The InitializeComponent() call 
        //  is required for Windows Forms designer support.
	//
	InitializeComponent();
			
	//
	// TODO: Add constructor code after the InitializeComponent() call.
	//
	dataGridView1.DefaultCellStyle.BackColor = Color.White;
	dataGridView1.DefaultCellStyle.ForeColor = Color.Black;
	dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Red;
	dataGridView1.DefaultCellStyle.SelectionForeColor = Color.White;
        dataGridView1.Refresh();
      }
		
   void Button1Click(object sender, EventArgs e)
   .
   .// the rest of program
   .




After inserting the four lines of code, and if at no point throughout the program you did not have changed,


sales_dataGridView1.DefaultCellStyle.BackColor
sales_sales_dataGridView1.DefaultCellStyle.ForeColor
sales_dataGridView1.DefaultCellStyle.SelectionBackColor
sales_dataGridView1.DefaultCellStyle.SelectionForeColor
or
sales_dataGridView1.CellStyle.BackColor
sales_sales_dataGridView1.CellStyle.ForeColor
sales_dataGridView1.CellStyle.SelectionBackColor
sales_dataGridView1.CellStyle.SelectionForeColor


the result should be:
cell color after the selection of cell by clicking on it is red,
cell color after entering into it for editing content,by double clicking on it or by pressing enter is white,
text color is always black and the color of the cell that is not selected is white.

If the problem still occurs that DataGridView background color matches the color of the text when you enter the cell to modify the content, then you should check all the places in the program, for eventually inserted code for change of colors.
If the program is made ​​in Visual Tool, where you just insert DataGridView from the Tool panel onto the Mainform,
check the properties for DataGridView DefaultCellStyle ,and check the properties in EditColumns Dialog for DataGridView DefaultCellStyle.Sometimes the color settings in these two different options are different from the settings in the program code and can override simetimes the program code if you use Reset command or Refresh command somewhere in the program.
Also, the difference in settings of colors in properties for DataGridView DefaultCellStyle , and the properties in EditColumns Dialog for DataGridView DefaultCellStyle usually results with unresolved error in program,
which you don't see (program running is apparently normal ,but it have errors).
This applies to all settings in those two properties for DataGredView control.

All the best,
Peric Zeljko
periczeljkosmederevo@y ahoo.com


这篇关于编辑时,Datagridview单元格背景变为黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆