我正在开发Windows移动应用程序。如何在网格中的数据表中仅显示十二列中的两列?
此外,是否可以删除Windows Mobile数据网格中的行?
请提供示例代码。
您好StartClass0830,
感谢您的回复,我不想删除网格中的列,让我们说在Windows移动应用程序中,dtNewOrder表包含11列,我需要显示从dtNewOrder到数据网格的某些字段。
另一个问题是datagrid包含10行我如何删除网格中的某些行。
请给我示例代码;我几天来一直在努力解决这个问题。
这就是我所拥有的:
Imports System.Data
Imports System.Text
Imports System.IO
Imports System.Data.SqlServerCe
Dim dtCustomerName As DataTable
Dim dtNewOrder As DataTable
Dim _objDataAccess As New DataAccess
Private Sub NewOrder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dtNewOrder = CreateNewOrderDataTable()
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
AddNewOrderMember(dtNewOrder)
End Sub
Private Sub AddNewOrderMember(ByVal dtNewOrder As DataTable)
Try
Dim NewOrderMemberRow As DataRow = dtNewOrder.NewRow()
NewOrderMemberRow("OrderID") = System.Guid.NewGuid()
NewOrderMemberRow("SalesPersonID") = "123"
NewOrderMemberRow("CustomerGroupID") = ddlCutomerGroup.SelectedValue.ToString()
NewOrderMemberRow("CustomerID") = ddlCustomerName.SelectedValue.ToString()
NewOrderMemberRow("CustomerItemCode") = "123"
NewOrderMemberRow("Category") = "Dummy Category"
'NewOrderMemberRow("Description") = "Dummy Des"
NewOrderMemberRow("OrderUnit") = "Each"
NewOrderMemberRow("OrderQuantity") = txtOrderQuantity.Text
NewOrderMemberRow("UnitPrice") = "123"
NewOrderMemberRow("TotalAmount") = "30000"
dtNewOrder.Rows.Add(NewOrderMemberRow)
dtNewOrder.AcceptChanges()
If dtNewOrder.Rows.Count > 0 Then
dgNewOrder.DataSource = dtNewOrder
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Mobile Retail Merchandising", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
End Try
End Sub
Private Function CreateNewOrderDataTable() As DataTable
dtNewOrder = New DataTable("NewOrder")
Try
dtNewOrder.Columns.Add(New DataColumn("OrderID", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("SalesPersonID", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("CustomerGroupID", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("CustomerID", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("CustomerItemCode", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("Category", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("Description", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("OrderUnit", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("OrderQuantity", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("UnitPrice", Type.GetType("System.String")))
dtNewOrder.Columns.Add(New DataColumn("TotalAmount", Type.GetType("System.String")))
Dim PrimaryKeyColumns() As DataColumn = New DataColumn(1) {}
PrimaryKeyColumns(0) = dtNewOrder.Columns("OrderID")
dtNewOrder.PrimaryKey = PrimaryKeyColumns
Return dtNewOrder
Catch ex As Exception
MessageBox.Show(ex.Message, "Mobile Retail Merchandising", MessageBoxButtons.OK, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1)
Return dtNewOrder
End Try
End Function
由于 BRITE
答案 0 :(得分:0)
你的问题有些问题。您在网格中提到了2列,在数据表中提到了12列,并且您想要删除ROWS!
我认为你的意思是COLUMNS而不是ROWS。对网格进行数据绑定时,可以指定所需的12个列。无需删除列。
如果您真的意味着ROWS,您可以修改SQL或LINQ查询以删除那些不需要的ROWS。