brdrok
asked on
Updating Data via DataGrid comboBox`
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
Thank you in advance
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
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
ASKER
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.OL EDB.4.0;Da ta Source=C:\\Documents and Settings\\toll\\My Documents\\Current Projects\\LibraryStatus\\L ibraryStat us.mdb;Per sist 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["NESingle s"];
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.GridColumnStyle s.Add(text Col);
}
else
{
DataGridComboBoxColumn comboTextCol = new DataGridComboBoxColumn();
comboTextCol.MappingName = "Status_FK";
comboTextCol.HeaderText = "myStatus";
comboTextCol.Width = 120;
comboTextCol.ColumnComboBo x.DataSour ce = myDataSet.Tables["Statuses "].Default View;
comboTextCol.ColumnComboBo x.DisplayM ember = "Status";
comboTextCol.ColumnComboBo x.ValueMem ber = "Status_ID";
tableStyle.PreferredRowHei ght = comboTextCol.ColumnComboBo x.Height + 2;
tableStyle.GridColumnStyle s.Add(comb oTextCol);
}
}
dgStatus.TableStyles.Clear ();
dgStatus.TableStyles.Add(t ableStyle) ;
dgStatus.DataSource = dt;
}
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.OL
string sqlString = "SELECT * FROM NESingles";
dataAdapter = null;
myDataSet = null;
try
{
connection = new OleDbConnection(connString
dataAdapter = new OleDbDataAdapter(sqlString
myDataSet = new DataSet();
dataAdapter.Fill(myDataSet
sqlString = "SELECT Status_ID, Status FROM Statuses";
dataAdapter = new OleDbDataAdapter(sqlString
dataAdapter.Fill(myDataSet
//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["NESingle
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.GridColumnStyle
}
else
{
DataGridComboBoxColumn comboTextCol = new DataGridComboBoxColumn();
comboTextCol.MappingName = "Status_FK";
comboTextCol.HeaderText = "myStatus";
comboTextCol.Width = 120;
comboTextCol.ColumnComboBo
comboTextCol.ColumnComboBo
comboTextCol.ColumnComboBo
tableStyle.PreferredRowHei
tableStyle.GridColumnStyle
}
}
dgStatus.TableStyles.Clear
dgStatus.TableStyles.Add(t
dgStatus.DataSource = dt;
}
ASKER
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
thanks
ASKER
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?