473,415 Members | 1,519 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,415 software developers and data experts.

Display records on the grid based on selected item in the combobox

26
i created a form that should function as follows:

i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a different item no in it..then, these records will be saved in a temporary datatable (which i made in a separate class, the name is WBASKET)...The item nos of these records will be displayed in a combobox, say item1, item2, etc..

then,i have a datagrid in the form..what will be displayed in it are those records saved in the Temporary datatable that i made, not directly querying from the database.

i already created a function that will let the program display on the grid the records that have the item no that i selected in the combobox...say i selected item1, then all records which has item1 in the temporary table will
be displayed on the grid.

//function for displaying records on the grid which has the same item no as the one selected in the combox
//wbasket is the temporary datatable that i made.
//Name: FillGridByItem()

DataTable dt = new DataTable();
dt = wbasket.DataTable.Clone();
int index = 0;
try
{
foreach(DataRow dr in wbasket.DataTable.Rows)
{
if(dr["item_no"].ToString().Trim() == cmbItems.SelectedItem.ToString().Trim())
{
DataRow dr2 = dt.NewRow();
int i = 0;
foreach(DataColumn dc in wbasket.DataTable.Columns)
{
dr2[i] = dr[dc.ColumnName];
i++;
}
dt.Rows.Add(dr2);
}
}
dgrWarehouse.DataSource = null;
dgrWarehouse.DataSource = dt;
}

after displaying all those records in the datagrid, once i click a record, then these data will be displayed in their corresponding textboxes...say i have a textbox for item name..then the item name field from my selected index in the grid will be displayed...(still the selected item in the combobox is the same as the item no that i clicked on the grid..)..up to there it is working fine.

the problem is this..say i have two items in the combobox. i selected the second item, example item2..then the program will display all records with item2..it will display the data to their corresponding textboxes, but when i click
the save button to update the temporary datable that i made,what is being updated is the first index, which is item1, not item2..

//UpdateGrid() function --being called when i click the save button

DataTable dt = (DataTable)(dgr1.DataSource);
if(dt.Rows.Count > 0)
{
if (dgrWarehouse.IsCellSelected)
{
DataRow dr = wbasket.DataTable.Rows[dgr1.CurrentRowIndex];
dr["quantity"]= txtQuantity.Text;
dr["name"] = txtName.Text
wbasket.DataTable.AcceptChanges();
FillGridByItem();
}

i hope you can help me with this...thanks..
Nov 13 '08 #1
2 3657
kurtzky
26
i know the error occurs in DataRow dr = wbasket.DataTable.Rows[dgrWarehouse.CurrentRowIndex]; under the UpdateGrid function, because the currentRowIndex of the grid is different from the wbasket's index, since i fill the grid by item no (FillGridByItem function)..

say i have displayed one item in the grid, which is item2..since i filtered it first based on the selected item in the combobox, item2 becomes the first index in the grid..but in the temporary datatable, the row number of item2 is 2...

but i don't know how to correct it.. :(
Nov 14 '08 #2
kurtzky
26
got it...it works fine now...:)
Nov 14 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Pete | last post by:
I have a combobox which is used to select records, which is satisfactory at the moment. However, a second user is going to start using this database and there will be 1600 records. This makes...
1
by: Seth Delaney | last post by:
I have a form with a combobox and a list box. The combobox will list records (names of queries) that are entered in a table called tblListName. I have the combobox set to get its values from this...
3
by: google | last post by:
This is something I've done plenty of times in '97, but I can't seem to get it to work correctly in Access 2003. Say, for example, I have a form with an unbound combobox, the data source is a...
4
by: Chris | last post by:
Any good routines or suggestions to assist me in re-ordering my records in my datagrid? i.e. I have a field in each record that is used for ordering (i.e. 1,2,3,4). I would like to implement a...
1
by: John Phelan-Cummings | last post by:
When I add the name of a new individual in a, bound form, it will not display that person’s name in a label control of a second unbound form. I have a scheduling program that I am working on. ...
1
by: BASSPU03 | last post by:
I've set my combobox to operate according to this option: "Find a record on my form based on a value I selected from my combobox." When I select a value from the combobox, I can see that the...
2
vikas251074
by: vikas251074 | last post by:
I am creating an application for official use. This application will be used by employees to take items for official use. I have a list, presently this list contains three items - 1) Cartridges, ...
1
Plater
by: Plater | last post by:
I feel like this question has been asked before, but I couldn't find it. I think I am missing something obvious. Basically I am going to have a DataGridView with two columns. One textbox, one...
12
by: ezechiel | last post by:
hi, the combobox is filled correctly and when I choose an item, the selected item is put into the DB by _AfterUpdate code. Row source: SELECT SOP.SOP_id, SOP.SOP_name, SOP.SOP_nr FROM SOP ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.