如何在文本框中使用值显示行到datagridview? [英] How to display rows to the datagridview with values in textbox?

查看:93
本文介绍了如何在文本框中使用值显示行到datagridview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在文本框中按Enter键时,其值将如何显示在datagridview中?

请帮忙.解释:我正在做销售表格.这里有txtitem和txtqty.当我在这些文本框中输入值并按Enter键时,txtitem.text和txtqty.text应该显示在datagridview和这些文本框中应该准备好输入下一个项目.这可能吗?我知道将值从db带到datagridview的代码,但是我不能这样做.帮助....

While pressing enter in a textbox, how it''s value will be displayed to the datagridview?

Please help.Explanatin: I''m doing a sales form.Here I have txtitem and txtqty.when I enter values to these textboxes and press enter key, the txtitem.text and txtqty.text should be displayed in a datagridview and these textboxs should be ready for next item to enter.Is this possible? I know the code to bring values from db to a datagridview, but I can''t do this .Help....

推荐答案

捕获keypress事件并检查如果按下Enter键,则读取文本框的当前值,并将此值添加到datagridview的数据源中,然后刷新datagridview
Catch the keypress event and check if the enter key is pressed, read the current value of the textbox and add this value to the datasource of the datagridview and then refresh the datagridview


制作一个DataSet
DataSet textData_DataSet = new DataSet();


在其中添加一个数据表


Add One Data Table in It

DataTable dtLocal = textData_DataSet.Tables["textData_DataTable"];
dtLocal.Columns.Add("txtitem", typeof(string));
dtLocal.Columns.Add("txtqty ", typeof(double));


每次在datagrid中添加数据时都要使Datarow每次在现有数据表"dtLocal"中添加新的原始数据,而每次要添加行时都不要创建新的数据表


Make Datarow each time you want to add data in datagrid add new raw each time in existing datatable "dtLocal" not making new datatable each time you want to add row

DataRow drLocal;
drLocal = dtLocal.NewRow();
drLocal["txtitem "] = txtitem.text.toString();
drLocal["txtqty "] = (double)txtqty.text;

dtLocal.Rows.Add(drLocal);



调用此方法刷新数据网格



Call this method to refresh datagrid

this.RefreshDatagrid(textData_DataSet);



每次添加数据时刷新DataGrid



Refresh DataGrid Each Time You Add Data

Public void RefreshDatagrid(DataSet datasetArg)
{
	yourDatagrid.DataSource = datasetArg.DefaultView;
}


这篇关于如何在文本框中使用值显示行到datagridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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