NoO*_*One 6 c# textbox datagridview visual-studio-2008 winforms
我使用eventhandler在DataGridView中为textbox创建了一个代码.
问题是当我单击另一个具有不同值的单元格时,单元格的背面颜色变为黑色.
例如:我在DataGridView
1 1000
2 2000
3 2000中有这些数据
当我点击1000时,我进展顺利.之后,我点击2000,当前单元格的背面颜色为黑色.但是,之后如果我点击其他2000,背面颜色再次变白.
因此,如果突出显示的单元格中的值发生更改,则会使背面颜色变为黑色.
有人可以帮我解决这个问题吗?
这是文本框的代码.
private void dgvSJ_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dgvSJ.CurrentCell.ColumnIndex == 10)
{
TextBox tx = e.Control as TextBox;
tx.TextChanged += new EventHandler(tx_TextChanging);
}
}
void tx_TextChanging(object sender, EventArgs e)
{
rowIndexCell = dgvSJ.CurrentRow.Index;
if (dgvSJ.Rows[rowIndexCell].Cells[10].EditedFormattedValue != null && dgvSJ.CurrentRow.Cells[10].EditedFormattedValue.ToString() != "")
{
dgvSJ.CurrentRow.Cells[10].Value = string.Format(GlobalVar.PriceFormat, Convert.ToDouble(dgvSJ.CurrentRow.Cells[10].EditedFormattedValue)); ![enter image description here][1]
}
}
Run Code Online (Sandbox Code Playgroud)
您可以使用 BackColor 属性更改文本控件的背景颜色,以融入窗体的配色方案。
XAML
<TextBox Height="23" HorizontalAlignment="Left" Margin="173,165,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" Background="Red" />
Run Code Online (Sandbox Code Playgroud)
C#
var tbox = new TextBox(){Background = color};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1008 次 |
| 最近记录: |