Solved

Updating Data via DataGrid comboBox`

Posted on 2004-10-19
6
219 Views
Last Modified: 2010-04-15
Hello Experts,

I have two MS Access tables that are related "Status" : "NESingles" (1:M).  PK: Status.Status_ID,  FK: NESingles.Status_FK

In my datagrid, I managed to show all the data inside the "NESingles" table and I have a comboBox column that shows the corresponding 'Status'.

When the user changes the 'Status' value of any "NESingles" record via the combobox inside my datagrid, how do I go about saving the data?  With what particular datagrid event do I get this started?  etc, etc, etc.

Hope I was able to explain this adequatly.  If not, please feel free to ask for further details.

Thank you very much



0
Comment
Question by:brdrok
  • 4
  • 2
6 Comments
 
LVL 7

Accepted Solution

by:
rohanbairat3 earned 460 total points
ID: 12350797
Hi ,

Typically what you should do is post back the form to itself onchange event .... u can use jaavscript to do that or just submit the form on change.....Also keep track of the changed value with hidden field. I am assuming that you are going to save the values after each change in status.

Once you send the form back you can retrive the value. The change can be tracked with the help of java script. You can assign values and text to a combo box ..the value can be the record id ...or any unique identifier.

so once the firm is submitted you can keep a routine for onpostback and save the changed values ...

You can deal with this in many ways ... you can also have an intermediate controller program to do this for you. Please let me know if this is clear or if i have confused u more ??

-rohan
0
 
LVL 7

Author Comment

by:brdrok
ID: 12350948
Hey Rohan,

thanks for getting back to me but I thought that I posted this underneath the C# area.  Wouldn't be the first time I posted a question in the wrong section.  Sounds to me like ASP.Net stuff.  Do you know how to do this w/o using ASP.Net?
0
 
LVL 7

Author Comment

by:brdrok
ID: 12351014
Also,  for my comboBox I have set the DisplayMember and the ValueMember as well.  Is there an event that traps when a user moves away from a certain column.  For example, a user changes a combobox value from "Option1" to "Option3" and then click away from that column.  I would like to capture that event and my ValueMember as well.

Thank you in advance
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 7

Expert Comment

by:rohanbairat3
ID: 12358653
Hi,

What language are you using for development. For combobox ..u can use OnChange Event ...You can write this in java script. The onChange event gets fired when u make a different selection in combobox so if option 1 is listed and u click option 3 then this event gets fired but if u drop down the box and make the same selection its not a change so u if u keep selecting same value the event wont fire which is perfectly right.

If you give more specifics .. i will paste some code if you want.

-rohan
0
 
LVL 7

Author Comment

by:brdrok
ID: 12358773
Hey Rohan,

I am attempting to use C# anyways :)  Still at the beginning stages of learning.  Below is the method that does the heavy lifting.  

private void MakeDataSetAndBindGrid()
{
      string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\toll\\My Documents\\Current Projects\\LibraryStatus\\LibraryStatus.mdb;Persist Security Info = False";

      string sqlString = "SELECT * FROM NESingles";

      dataAdapter = null;
      myDataSet = null;

      try
      {
            connection = new OleDbConnection(connString);

            dataAdapter = new OleDbDataAdapter(sqlString, connection);
            myDataSet = new DataSet();
            dataAdapter.Fill(myDataSet, "NESingles");

            sqlString = "SELECT Status_ID, Status FROM Statuses";

            dataAdapter = new OleDbDataAdapter(sqlString, connection);
            dataAdapter.Fill(myDataSet, "Statuses");

            //connection.Close();
      }
      catch (Exception ex)
      {
            MessageBox.Show("Problem with DB access-\n\n connection: "
            + connString + "\r\n\r\n                      query: " + sqlString
            + "\r\n\r\n\r\n" + ex.ToString());

            this.Close();
            return;
      }

      DataGridTableStyle tableStyle = new DataGridTableStyle();
      tableStyle.MappingName = "NESingles";

      DataTable dt = myDataSet.Tables["NESingles"];

      for(int i = 0; i < dt.Columns.Count; ++i)
      {
            if(i != 8)
            {
                  DataGridTextBoxColumn textCol = new DataGridTextBoxColumn();
                  textCol.MappingName = dt.Columns[i].ColumnName;
                  textCol.HeaderText = dt.Columns[i].ColumnName;
                  tableStyle.GridColumnStyles.Add(textCol);
            }
            else
            {
                  DataGridComboBoxColumn comboTextCol = new DataGridComboBoxColumn();
                  comboTextCol.MappingName = "Status_FK";

                  comboTextCol.HeaderText = "myStatus";
                  comboTextCol.Width = 120;
                  comboTextCol.ColumnComboBox.DataSource = myDataSet.Tables["Statuses"].DefaultView;
                  comboTextCol.ColumnComboBox.DisplayMember = "Status";
                  comboTextCol.ColumnComboBox.ValueMember = "Status_ID";

                  tableStyle.PreferredRowHeight = comboTextCol.ColumnComboBox.Height + 2;

                  tableStyle.GridColumnStyles.Add(comboTextCol);
            }
      }

      dgStatus.TableStyles.Clear();
      dgStatus.TableStyles.Add(tableStyle);
      dgStatus.DataSource = dt;
}
0
 
LVL 7

Author Comment

by:brdrok
ID: 12359560
Hey Rohan, in the event that you are still working on this question....i want to let you know that i am deleting this question.  i appreciate your comments.  turns out that i set the datasource to a datatable and i should have set it to a dataset.

thanks

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now