所以基本上我创建了7列[Particular] ,[Category] ,[Warranty] ,[Name] [Description] ,[Stocks],[Orders]
[Particular] ,[Category]
和[Warranty]
列是使用DataTable
创建的,并且位于Form_load Event
Dim tbl As New DataTable
tbl.Columns.Add("Particular")
tbl.Columns.Add("Category")
tbl.Columns.Add("Warranty")
tbl.Rows.Add("Select Particular", "Select Category", "Select Warranty")
GridControl.DataSource = dtbl
使用UnBoundColumnData
创建剩余的4列此列将接收我要导入的Excel文件
我如何创建列,也可以位于Form_Load event
Dim Fields() As String = {"NAME", "DESCRIPTION", "STOCK", "ORDERED"}
Dim View As ColumnView = GridControl1.MainView
Dim gc3 As New GridColumn
For i As Integer = 0 To Fields.Length - 1
gc3 = GridView1.Columns.AddField(Fields(i))
gc3.VisibleIndex = View.Columns.Count
gc3.UnboundType = UnboundColumnType.String
Next
然后我为特殊类别保修列创建了RepositoryItemComboBox
,并且位于GridView1_CustomRowCellEdit Event
Dim rcb As RepositoryItemComboBox
rcb = New RepositoryItemComboBox
rcb.Items.Add("AA")
rcb.Items.Add("BB")
rcb.Items.Add("CC")
GridView1.Columns("Particular").ColumnEdit = rcb
这会填充特定列并生成ColumnEdit = RepositoryItemComboBox
现在,当我加载表单而不导入Excel文件时,[Particular]
列中的值即使在我聚焦到不同的行时也会保留。但是当我开始导入excel文件然后尝试从RepositoryItemComboBox
中选择一个项目时它会在我关注不同的行时清除值
我真的需要一些帮助,因为我不知道如何保持这些价值观。谢谢
答案 0 :(得分:0)
从Excel加载数据后,您必须添加未绑定的列。
private void FillExcelToGrid() {
var tbl = GetExcelAsDataTable(); // this method wraps your existing code, you return the datatabele
tbl.Columns.Add("Particular")
tbl.Columns.Add("Category")
tbl.Columns.Add("Warranty")
for (var ii = 0; ii < tbl.Rows.Count; ii++) {
tbl.Rows[ii]["Particular"] = "Select Particular";
tbl.Rows[ii]["Category"] = "Select Category";
tbl.Rows[ii]["Warranty"] = "Select Warranty";
}
GridControl.DataSource = tbl;
}