向datagidview添加新行 [英] Adding a new row to the datagidview

查看:215
本文介绍了向datagidview添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我有一个带有一些记录的datagridview,下面是一个Button(Add),当我单击它导航到另一个表单时,该按钮将导航到另一个表单,并且该表单包含文本框和一个按钮,当我填充这些txtbox并按按钮,它正在导航到父表单以及文本框的值,现在我的要求是我想创建一个新行并将这些文本框的值放入datagridview新创建的单元格中,请帮助我.

解决方案

由于您已经编写了表单",因此假设它是一个winform应用程序.

我从您的问题中了解到的是,当您返回到网格表单时,您希望文本框的值反映在网格中.如果我错了请纠正我.
我的遮阳篷将是:您首先应该让gridview具有作为DataGridViewTextBoxColumn的列.现在,您可能将datagridview与某些集合对象(如arraylist)或DataTable绑定了.您可以做的是在编辑表单中将输入的值添加到集合中.当您从编辑表单返回到网格时,只需再次将网格与集合对象重新绑定即可.如果我正确理解了您的问题,希望这可以解决您的问题.
等待您对此的回应.


hi I have a datagridview with some records and below that a Button(Add) is there whenever i click on that it is navigating to another form and that form contain textbox''s and a button, when i filled those txtbox''s and press the button it is navigating to parent form along with the textbox''s value now my rquirement is i want to create a new row and putting those textbox''s values into the datagridview newly created cells,Please help me.

解决方案

Since you have written "Form" there so am assuming this to be a winform app.

What i have understood from your question is when you return back to the grid form you want the values of textbox to be reflected in grid. Correct me if i am wrong.
My awnser to this will be: You should first let the gridview have columns as DataGridViewTextBoxColumn. Now You might be binding the datagridview with some collection object(like arraylist) or DataTable. What you can do is in the edit form add the values entered to the collection. when you come back from the edit form to grid just rebind the grid again with the collection object. Hope this will solve your problem if i''ve understood your question correctly.
Waiting for your response on this.


这篇关于向datagidview添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆