?
Solved

update value in a DataGridView c#

Posted on 2010-09-02
3
Medium Priority
?
791 Views
Last Modified: 2012-05-10
I am trying to upate particular cells in a grid, The gird is already populated with values, and i have a button that I want to update every row on the grid , but only a particular cell in the grid

Here is what I have so far but I am getting stuck on how to update the data on the grid ...

        private void ApplyAllButton_Click
                    (object sender
                    ,EventArgs e
                    ,string lv_CustomerID)
        {
            int rownum = 0;
            string temp_msg = "";

            Dictionary<string, string> UpdateValues;
            UpdateValues.Add("SalesPrice", "");
            UpdateValues.Add("BasePrice", "");
            UpdateValues.Add("DiscountPerc", "");
            UpdateValues.Add("DiscountType", "");
            UpdateValues.Add("Authorized", "");
            UpdateValues.Add("NetPrice", "");

            dataGridView1 = SaveLocal(dataGridView1, MacStockCheckDic.Stock_check_columns());

            if (g_debug_level > 1) { temp_msg = "oracleProcedure"; }

            //if (CustomerID.Text == String.Empty)
            if (lv_CustomerID == "")
            {
                MessageBox.Show("No Customer ID has been entered, customer information related \n"
                                +"to the parts you have chosen will not be updated.\n"
                                +"Please check to make sure you have a Valid Customer ID. \n"
                                 , "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //do a check to see if the customer exists in IFS
            }
            else
            {
                foreach (DataGridViewRow GridRow in dataGridView1.Rows)
                {
                    //get the data from the row that you need to update into a dictionary
                    foreach (KeyValuePair<string, string> MACViewColsPair in MACVW_STOCK_CHECK_ColDictionary)
                    {
                        StockCheckColDictionary[MACViewColsPair.Key] = GridRow.Cells[MACViewColsPair.Value].ToString();
                    }

                    // update the dictionary with the updated values
                    MacOraIFS.UpdateStockCheckColumns_from_MAC_PRICING_API_Get_Price
                               (StockCheckColDictionary
                               , dbenviroment
                               , lv_CustomerID
                               , "10"
                               , OracleDbConn);
 
                    //update the grid cells based on the values i have in the dictionary
                    // this is where i have the problem
                    // the UpdateValues Dictionary has the coloumn names of the grid that I want to
                   // update..
                   foreach (KeyValuePair<string, string> UpdateValuesPair in UpdateValues)
                    {
                        GridRow.Cells[UpdateValuesPair.Key] = "1";
                            //StockCheckColDictionary[UpdateValuesPair.Key];
                    }


                }
            }

        }
0
Comment
Question by:jhacharya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 16

Expert Comment

by:kris_per
ID: 33590130

What is in 'MACVW_STOCK_CHECK_ColDictionary'?
0
 
LVL 2

Accepted Solution

by:
jhacharya earned 0 total points
ID: 33591732
I have got a completed version which complies if anyone wants to use it, the MACVW_STOCK_CHECKColDictionary, is a dictionary of the column names that I was interested in

        public void UpdateDataGridRow
                (Dictionary<string, string> lv_StockCheckGridCols
                , Dictionary<string, string> lv_ColumnFormatGridViewDictionary
                , Dictionary<string, string> lv_ColumnsUpdatedGridViewDictionary
                , DataGridViewRow lv_GridRow)
        {
            try
            {
                // this is to populate the data table and bind to the datagrid
                Decimal TempValueCurrency;
                DateTime TempValueDate;

                foreach (KeyValuePair<string, string> UpdateValuesPair in lv_ColumnsUpdatedGridViewDictionary)
                {
                    if (lv_StockCheckGridCols[UpdateValuesPair.Key] != "")
                    {
                        switch (lv_ColumnFormatGridViewDictionary[UpdateValuesPair.Key])
                        {
                            case "N":
                                {
                                    TempValueCurrency = Convert.ToDecimal(lv_StockCheckGridCols[UpdateValuesPair.Key]);
                                    lv_GridRow.Cells[UpdateValuesPair.Key].Value = TempValueCurrency.ToString("c");
                                    break;
                                }
                            case "D":
                                {
                                    //TempValueDate = Convert.ToDateTime(StockCheckPair.Value);
                                    //myNewRow[StockCheckPair.Key] = TempValueDate.ToString("c");
                                    lv_GridRow.Cells[UpdateValuesPair.Key].Value = lv_StockCheckGridCols[UpdateValuesPair.Key];
                                    break;
                                }

                            case "S":
                                {
                                    lv_GridRow.Cells[UpdateValuesPair.Key].Value = lv_StockCheckGridCols[UpdateValuesPair.Key];
                                    break;
                                }
                            default:
                                {
                                    lv_GridRow.Cells[UpdateValuesPair.Key].Value = lv_StockCheckGridCols[UpdateValuesPair.Key];
                                    break;
                                }
                        }
                    }
                    else
                    {
                        lv_GridRow.Cells[UpdateValuesPair.Key].Value = lv_StockCheckGridCols[UpdateValuesPair.Key];
                    }
                }
            }
            catch (Exception err)
            {
                Console.WriteLine("<b>Message:</b> " + err.Message
                                  + "<br /><br />"
                                  + "<b>Source:</b> " + err.Source
                                  + "<br /><br />"
                                  + "<b>Stack Trace:</b> " + err.StackTrace);
            }

        }//public void UpdateDataGridRow
0
 
LVL 2

Author Closing Comment

by:jhacharya
ID: 33591739
this procedure updates particular columns on the  row of the grid view in Win forms
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question