Click here to Skip to main content
13,143,628 members (31,188 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I have a DataGridview and a text box in form application.
user is entering ID in the text box and enter.
according to ID data is getting filled in the DataGridview.
Let here total 5 items are getting filled in the Datagridview .
Next Here I want that If user Again entering another ID in the Textbox.
I want that the fetched data should just get filled below the previous Data.
I mean to say that new data should get filled below those 5 items fetched earlier in the Datagridview.

Please suggest some Ideas .
Help needed.
Posted 7-Nov-12 0:07am
Updated 7-Nov-12 0:40am
Shahan Ayyub 7-Nov-12 6:13am
How do you do :
>>according to ID data is getting filled in the DataGridview.
I mean to say how do you populate data in row ? Have you tried to add a new row in grid and target it to populate with data ?
Karwa_Vivek 7-Nov-12 6:31am
i am setting the Datasource to the datagridview.
faisal23 7-Nov-12 7:02am
You are setting datasource to the gridview, so on form load it is binded. When you enter id from text box so you have to use concate the existing grid values
Karwa_Vivek 7-Nov-12 7:03am
Can you explain this a little Bit
faisal23 7-Nov-12 7:04am
use gv.items.add() function
saikishore1979007 26-Mar-14 1:53am
im new to this kind of model,can anybody please give me some code on this model

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Once you set DataSource property of datagridview it overrides the previously datasource if source assigned. That is why you are getting only those records which were recently requested.

I would suggest it to fix with two ways:

1) Collect all IDs in either a "string" (comma separated) or "List(of Integer)" and pass these Ids every time you fetch data from database. Using this way "DataSource" way would work.

2) Don't set DataSource property of DataGridView instead, iterate on all rows of DataTable/DataSet (which were set to DataSource property) and use
DataGridView.Rows.Add() methods something like this:

This piece of code can provide you an idea on how to accomplish task:(untested)

Dim dt as DataTable = RetrieveDataTable()   ' Gets records in DataTable according to Ids user entered uptil now
For Each row as DataRow in dt.Rows
   DataGridView1.Rows.Add(new Object() { row(0), row(1),....}) '' access elements from "dt" and add in the datagridview's row

Hope it helps!
Karwa_Vivek 7-Nov-12 7:16am
I think you can help me.
Please explain your second way more.
Shahan Ayyub 7-Nov-12 8:05am
I assumed "RetrieveDataTable" is a method that will fetch data from database according to the id user entered. Say for example user enter id = 1. this method will retrieve all info related to id=1 in datatable using SqlDataAdapter.Fill method. In next step you can iterate using for loop on all rows exists in DataTable and call DataGridView1.Rows.Add() method to append these row at the end of datagridview. Is it clear now ? In case no please provide details about the issue which is still unclear.
Karwa_Vivek 7-Nov-12 8:30am
I want to clear my query More .
Let for Example user enter id =1 and Fetched the related Data in datagridview.
Now next user enter id =2 .here I just want that the related data with id 2. will get filled just below the related data with id 1 previously user has entered.
I have understood the "RetriveDataTable" method.which will fetch the data related to ID =1.. but what to do when user enter ID =2 and again press enter.Here the Requirement is that Datagridview should not get clear only the data related to ID =2 get filled below it.
Shahan Ayyub 7-Nov-12 8:37am
If you noticed my updated solution you will see i have not cleared Rows of grid. so if "RetrieveDataTable" retrieves data for id=1 and filled grid, later user entered id=2, here rows are "as it is". So "DataGridView1.Rows.Add()" will add another row in grid with data of id=2. Now you have two rows in grid one for id=1 and one for id=2.
Shahan Ayyub 7-Nov-12 11:34am
Is it clear now ?
saikishore1979007 26-Mar-14 1:54am
can anybody give me a example of this model
Shahan Ayyub 31-Mar-14 13:25pm
@saikishore1979007, beside this solution i just ended up a brief solution on how to append the new result set with the previous one here: with a bunch of performance evaluation. Hope it helps!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170915.1 | Last Updated 7 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100