VB中listview如何给同一行的每一列加内容
2011-07-11
展开全部
Private Sub Form_Load()
Dim i, j As Long
Dim tmpLI As ListItem
With ListView1
For i = 1 To 3
.ColumnHeaders.Add , , "列" & i
Next i
For i = 1 To 3
Set tmpLI = .ListItems.Add(, , (i - 1) * 3 + 1)
For j = 1 To 2
tmpLI.SubItems(j) = (i - 1) * 3 + 1 + j
Next j
Next i
.View = lvwReport
End With
End Sub
Dim i, j As Long
Dim tmpLI As ListItem
With ListView1
For i = 1 To 3
.ColumnHeaders.Add , , "列" & i
Next i
For i = 1 To 3
Set tmpLI = .ListItems.Add(, , (i - 1) * 3 + 1)
For j = 1 To 2
tmpLI.SubItems(j) = (i - 1) * 3 + 1 + j
Next j
Next i
.View = lvwReport
End With
End Sub
展开全部
//更新数据
protected void gvOrderInfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//获取要更新的行
var row = gvOrderInfo.Rows[e.RowIndex];
//提取单价字段的值
gvOrderInfo.Columns[2].ExtractValuesFromCell(e.NewValues, row.Cells[2] as DataControlFieldCell, DataControlRowState.Edit, true);
//提取数量字段的值
gvOrderInfo.Columns[3].ExtractValuesFromCell(e.NewValues, row.Cells[3] as DataControlFieldCell, DataControlRowState.Edit, true);
//提取金额字段的值
gvOrderInfo.Columns[4].ExtractValuesFromCell(e.NewValues, row.Cells[4] as DataControlFieldCell, DataControlRowState.Edit, true);
var price=e.NewValues["Price"].ToString();
var num = e.NewValues["Number"].ToString();
var money = e.NewValues["Money"].ToString();
string bookId = gvOrderInfo.DataKeys[e.RowIndex].Value.ToString();
List<OrderInfo> list=ViewState["list"] as List<OrderInfo>;
OrderInfo order = list.Find(ee => ee.BookID == bookId);
if (order != null)
{
order.Number = int.Parse(num);
order.Money = decimal.Parse(price) * order.Number;
}
gvOrderInfo.EditIndex = -1;
gvOrderInfo.DataSource = list;
gvOrderInfo.DataBind();
Count();
}
里面的代码貌似实现了那个功能,最主要的是List<T>的Find()方法
protected void gvOrderInfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//获取要更新的行
var row = gvOrderInfo.Rows[e.RowIndex];
//提取单价字段的值
gvOrderInfo.Columns[2].ExtractValuesFromCell(e.NewValues, row.Cells[2] as DataControlFieldCell, DataControlRowState.Edit, true);
//提取数量字段的值
gvOrderInfo.Columns[3].ExtractValuesFromCell(e.NewValues, row.Cells[3] as DataControlFieldCell, DataControlRowState.Edit, true);
//提取金额字段的值
gvOrderInfo.Columns[4].ExtractValuesFromCell(e.NewValues, row.Cells[4] as DataControlFieldCell, DataControlRowState.Edit, true);
var price=e.NewValues["Price"].ToString();
var num = e.NewValues["Number"].ToString();
var money = e.NewValues["Money"].ToString();
string bookId = gvOrderInfo.DataKeys[e.RowIndex].Value.ToString();
List<OrderInfo> list=ViewState["list"] as List<OrderInfo>;
OrderInfo order = list.Find(ee => ee.BookID == bookId);
if (order != null)
{
order.Number = int.Parse(num);
order.Money = decimal.Parse(price) * order.Number;
}
gvOrderInfo.EditIndex = -1;
gvOrderInfo.DataSource = list;
gvOrderInfo.DataBind();
Count();
}
里面的代码貌似实现了那个功能,最主要的是List<T>的Find()方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询