Solved

update value in a DataGridView c#

Posted on 2010-09-02
3
787 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

687 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