如何在Gridview WInform中存储数据?

编程入门 行业动态 更新时间:2024-10-28 19:21:44
本文介绍了如何在Gridview WInform中存储数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的表单中,用户从下拉框中选择客户。我将客户发票填入gridview。现在我想将发票号和发票金额存储到数组中。如何完成这项任务? 我尝试了这段代码但只获得了最后一行gridview

Hi, In my form user select the customer from dropdown box. I populate the customer invoice's into gridview. Now I want to store that invoice no and invoice amount into array. How to complete this task ? I tried this code but getting last row of gridview only

for (int i = 0; i < gridView2.RowCount; i++) { invno = gridView2.GetRowCellValue(i, "InvoiceId"); int[] invid = new int[] { Convert.ToInt32(invno) }; }

推荐答案

在这里,您可以找到有关.NET和C#中数组的一些信息: msdn.microsoft/en-us/library/ aa288453%28v = vs.71%29.aspx [ ^ ] 我认为在这种情况下,数组不是一个好选择。为什么不使用Dictionary? 假设您在gridView中存储数据,如下所示:InvoiceId(Int32)和TotalAmount(Double),请尝试使用此代码: Here you find some informations about arrays in .NET and C#: msdn.microsoft/en-us/library/aa288453%28v=vs.71%29.aspx[^] I think that array is not good choice in this case. Why not to use Dictionary? Assuming that you are storing data in gridView in fields like this: InvoiceId (Int32) and TotalAmount (Double), try to use this code: var invoices = new Dictionary<int,double>() for (int i = 0; i < gridView2.RowCount; i++) { invNo = gridView2.GetRowCellValue(i, "InvoiceId"); invAmount = gridView2.GetRowCellValue(i, "TotalAmount"); invoices.Add(invNumber, invAmount); }

您可以像这样迭代字典:

The you can iterate through you dictionary like this:

foreach (int invoiceId in invoices.Keys) { double invoiceAmount = invoices[invoiceId] Console.WriteLine(string.Format("Invoice: {0}, Total amount: {1}", invoiceId, invoiceAmount)); }

希望能帮助你:)

Hope that help you :)

更多推荐

如何在Gridview WInform中存储数据?

本文发布于:2023-11-11 17:03:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579047.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   如何在   Gridview   WInform

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!