Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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....
Posted
Updated 3-May-11 23:20pm
v3
Comments
Sandeep Mewara 4-May-11 4:42am    
Not clear. Care to elaborate what you mean by displayin grid? Reason... workflow? Any effort?

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
 
Share this answer
 
Make one 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));

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);


Refresh DataGrid Each Time You Add Data

Public void RefreshDatagrid(DataSet datasetArg)
{
	yourDatagrid.DataSource = datasetArg.DefaultView;
}
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900