473,386 Members | 1,820 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,386 software developers and data experts.

Specific DataGridView Row Selection

BRawn
28
Hi Guys,

I'm busy working on an Orders project, but I'm a bit stuck where I am now. I have a Products DGV and a Basket DGV. Initially, when an order is placed I write to 3 tables in my database which was tricky but that all works fine.

What I'm having a bit of trouble with now is:

Once an order is placed and for some reason the order needs to be edited, I want to select only the new items in the Basket DGV.

For clarity, when the Order form loads (for edit) the basket DGV gets populated with the items that were originally selected for that order. I'm a bit stuck here because I'm not too sure how to select only the newly added items for the order.

Lets say the order had 8 items and I add 2 more, the basket DGV would now have 10 items. I don't want to loop through the DGV again and rewrite all the values in the DGV back to my database. That's what's happening now. There WERE 8 items, now after the edit, there are 18 (the 8 original and the 10 [8 + 2] from the edit).

Is there a way to get ONLY the 2 new items?

I've thinking about using a boolean flag to check if the product already exists in the basket, but I'm not too sure how to say, in code 'if the product exists, ignore it and select only the products that weren't there'.

I have the following to populate my basket DGV for the edit part:

Expand|Select|Wrap|Line Numbers
  1.  
  2. void populatedgvBasketForEdit()
  3.         {
  4.             dgvBasket.Rows.Clear();
  5.             Hashtable columns = new Hashtable();
  6.  
  7.             initialAvailableStock();
  8.  
  9.             DataSet ds = new DataSet();
  10.             ds = orderMethods.populateBasketDGVForEdit(ds, _orderNumber);
  11.  
  12.             columns.Add("ProductID", "INT:0");
  13.             columns.Add("ProductName", "STRING:1");
  14.             columns.Add("QuantityOrdered", "INT:2");
  15.  
  16.             orderMethods.populateBasketDGV(ds, dgvBasket, columns, _orderNumber);
  17.         }
  18.  
  19.  
This works and it only shows the existing order. The order can be however long or however short; I just don't want these items to be added again.

Any suggestions?

Please let me know if I need to post more code. I use quite a lot of loops to achieve the desired results...

Thanks
Nov 3 '10 #1
1 2075
BRawn
28
Since it seems there's no one that really knows how to achieve the result I'm looking for, I've written some code which works halfway :P

Here it is:

Expand|Select|Wrap|Line Numbers
  1.  
  2. void arrayTest()
  3.         {
  4.             int multiArrayCounter = 0;
  5.             int singleArrayCounter = 0;
  6.             bool productExists = false;
  7.  
  8.             string[,] existingItems = new string[dgvBasket.Rows.Count, 2];
  9.  
  10.             for (int i = 0; i < dgvBasket.Rows.Count; i++)
  11.             {
  12.                 existingItems[multiArrayCounter, 0] = dgvBasket.Rows[i].Cells[1].Value.ToString().Trim();
  13.                 _productName = dgvBasket.Rows[i].Cells[1].Value.ToString().Trim();
  14.                 _productID = orderMethods.returnProductID(_productName);
  15.  
  16.                 existingItems[multiArrayCounter, 1] = dgvLineItems.Rows[i].Cells[2].Value.ToString().Trim();
  17.                 multiArrayCounter++;
  18.                 //productExists = true;
  19.             }
  20.             _testCountTotal = multiArrayCounter;
  21.  
  22.             DataSet ds = new DataSet();
  23.             ds = orderMethods.populateBasketDGVForEdit(ds, _orderNumber);
  24.  
  25.             foreach (string s in existingItems)
  26.             {
  27.                 foreach (DataRow dr in ds.Tables[0].Rows)
  28.                 {
  29.                     if (dr["ProductName"].ToString().Trim() == s)
  30.                     {
  31.                         string[] newItems = new string[dgvBasket.Rows.Count - _testCountTotal];
  32.  
  33.                         for (int k = 0; k < dgvBasket.Rows.Count; k++)
  34.                         {
  35.                             newItems[singleArrayCounter] = dgvBasket.Rows[k].Cells[1].Value.ToString().Trim();
  36.                             singleArrayCounter++;
  37.                             productExists = false;
  38.                         }
  39.                     }
  40.                     else
  41.                     {
  42.                         getExistingItems();
  43.                     }
  44.                 }
  45.             }
  46.         }
  47.  
  48.  

As I've mentioned, this works like halfway. What I'm doing here is filling a multidimensional array with the products that were already there, then, from there, I'm trying to build another array with the items that came afterwards.

I've managed to fill the multidimensional array but I'm struggling to get only the items that were appended to the order. Any ideas from here?

Thanks again :)
Nov 3 '10 #2

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

Similar topics

1
by: hazz | last post by:
I am simply trying to obtain the value of a specific cell ( a CustomerID in a particular row.) in a DataGridView. How (or can I ) do this using the RowEnter event? The datagrid is bound to a...
0
by: Michel Lapointe | last post by:
Hello, I would like to know if there is an event for the Datagridview control that is trigger before the selection change and is cancelable. I'm currently using the SelectionChanged event...
0
by: Paul Cheetham | last post by:
Hi, I have a DataGridView Control, which I am databinding at run-time. When the data is loaded, the first row in the grid gets selected, and the selectionChanged event gets fired. I want the...
0
by: Paul Cheetham | last post by:
Hi, I have a DataGridView control, where I am setting its Datasource property to a datatable. The DataGridView has it's MultiSelect property set to false I also have a handler for the...
2
by: martin1 | last post by:
Hi, All, The datagridview auto-select first column first row data and the slected cell background color is blue, so how to turn off the select? or how to change selected cell backcolor to white?...
2
by: Rick Shaw | last post by:
Hi, I have a problem with the datagridview not refreshed when the application first appear on the screen. The datagridview display data from a table in the dataset. At the same time, I've added...
0
by: DBC User | last post by:
I have a datagridview and there are 4 coulmns, the user could do sort on any of the columns. After doing sorting. The user could do refresh the datagridview and get another set of data. But when I...
0
by: nareshg1 | last post by:
Hi all, I am trying to display four datagridviews which has fixed size. I am displaying these grids on panel, It is like template. All grids scroll bar are disable. When i scroll vertically...
2
by: ValValVal | last post by:
Hi all. I have a JTable with 5 columns. Cell Selection is ON. I want to disable user's ability to select any cell that is on 0-th column. Can't find any info on how to cope with it. Thanks in...
0
by: lenniekuah | last post by:
Hi Fellow Good Guys, I need your help, Please Help me. Surprising I encounterd another problem which never happened in VB.NET but in C# technique it causing problem. Here is the explanation...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.