在GridView中的空单元格中显示消息 [英] Show message in empty cells in GridView
本文介绍了在GridView中的空单元格中显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从excel
导入 GridView
我需要在每个空单元格附近显示一条消息,以向用户提供有关应写入的信息。
void simpleButton1_Click(object sender,System.EventArgs e)
{
string [] msg = new串[60];
string [] error = new string [400]; (int i = 0; i< gridView3.RowCount; i ++)
{
System.Data.DataRow Rows = gridView3.GetDataRow(i);
string cellvalue = Rows [0] .ToString();
if(cellvalue ==)
{
msg [0] =Missing'First Name';
error [i] = msg [0] + - ;
}
cellvalue = Rows [1] .ToString();
if(cellvalue ==)
{
msg [1] =Missing'Last Name';
error [i] + = msg [1] + - ;
}
// ...
}
}
如何将变量 msg []
添加到具有小图像的特定单元格,或!
你可以使用
样式格式条件
自定义绘画(样本)
I'm importing GridView
from excel
I need to show a message near every empty cell to give the user information about what it should be writing..
void simpleButton1_Click(object sender, System.EventArgs e)
{
string[] msg = new string[60];
string[] error = new string[400];
for (int i = 0; i < gridView3.RowCount ; i++)
{
System.Data.DataRow Rows = gridView3.GetDataRow(i);
string cellvalue = Rows[0].ToString();
if (cellvalue == "")
{
msg[0] = "Missing 'First Name'";
error[i] = msg[0] + " - ";
}
cellvalue = Rows[1].ToString();
if (cellvalue == "")
{
msg[1] = "Missing 'Last Name'";
error[i] += msg[1] + " - ";
}
//...
}
}
How can I put the variable msg[]
to the specific cell with a little image or "!"
figure or maybe I can color the cell
解决方案
You can color the XtraGrid cells using Conditional Formatting feature:
gridControl1.DataSource = new List<Person> {
new Person(){ Name = "John", Age = 25 },
new Person(){ Name = "Mary", Age = 17 },
new Person(){ Age = 17 },
new Person(){ Name = "Ann" },
new Person(){ Name = "Pit", Age = 5 },
};
StyleFormatCondition nameCondition = new StyleFormatCondition();
nameCondition.Column = gridView1.Columns["Name"];
nameCondition.Condition = FormatConditionEnum.Expression;
nameCondition.Expression = "IsNullOrEmpty([Name])";
nameCondition.Appearance.BackColor = Color.Red;
nameCondition.Appearance.Options.UseBackColor = true;
StyleFormatCondition ageCondition = new StyleFormatCondition();
ageCondition.Column = gridView1.Columns["Age"];
ageCondition.Condition = FormatConditionEnum.Expression;
ageCondition.Expression = "[Age]<10";
ageCondition.Appearance.BackColor = Color.Maroon;
ageCondition.Appearance.Options.UseBackColor = true;
gridView1.FormatConditions.AddRange(new StyleFormatCondition[] {
nameCondition, ageCondition
});
Result:
Related Links:
Customizing Appearances of Individual Rows and Cells
Style Format Conditions
Custom Painting (Samples)
这篇关于在GridView中的空单元格中显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文