|
-
Feb 24th, 2010, 12:29 AM
#1
Thread Starter
Member
[Ressolved] DataGridViewComboBoxColumn SelectedIndexChanged Event
Dear Experts,
I am using a datagridview (C# .NET) with one combobox column and two textbox columns. What I want if user select a value from combobox then program fires a query against the combobox value and populate result in textbox (within the same row). Everything is fine besides that textbox is not getting update instantly. Its being updated after click on another cell and sometimes after many clicks. I m using following code:
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
if(dataGridView1.CurrentCell.EditType.ToString()== "System.Windows.Forms.DataGridViewComboBoxEditingControl")
{
SendKeys.Send ("{F4}");
intRowNum = e.RowIndex;
}
}
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox combo = e.Control as ComboBox;
if (combo != null)
{
// Remove an existing event-handler, if present, to avoid adding multiple handlers when the editing control is reused
combo.SelectedIndexChanged -= new EventHandler(ComboBox_SelectedIndexChanged);
// Add the event handler.
combo.SelectedIndexChanged += new EventHandler(ComboBox_SelectedIndexChanged);
}
}
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
DataSet ds = new DataSet();
OdbcDataAdapter daSQL;
try
{
string strSQL = "SELECT A.ADVVR_OMSCHRIJVING FROM BVK_VRAGEN_ADVIESBIJVRAAG A, BVK_VRAGEN_REL_ANTWOORDADVIES B, BVK_VRAGEN C, BVK_VRAGEN_ANTWOORDMOGELIJKHEDEN D WHERE A.ADVVR_ID = b.ADVVR_ID AND B.VRG_ID = C.VRG_ID and B.ANTWM_ID = D.ANTWM_ID and C.VRG_CODE = '" + dataGridView1.Rows[intRowNum].Cells[0].Value + "' AND D.ANTWM_OMSCHRIJVING = '" + dataGridView1.Rows[intRowNum].Cells[2].Value + "'";
OdbcCommand cmd = new OdbcCommand(strSQL, clsGloabalDeclearation.cnSQL);
//Get the record from the daSQLtabase
daSQL = new OdbcDataAdapter(strSQL, clsGloabalDeclearation.cnSQL);
//Fill filtered daSQLta in daSQLtaset
daSQL.Fill(ds, "BVK_VRAGEN_ADVIESBIJVRAAG");
if (ds.Tables["BVK_VRAGEN_ADVIESBIJVRAAG"].Rows.Count > 0)
{
dataGridView1.Rows[intRowNum].Cells[3].Value = ds.Tables["BVK_VRAGEN_ADVIESBIJVRAAG"].Rows[0][0].ToString();
dataGridView1.Update();
}
}
catch (Exception ex)
{
//If any error occured
MessageBox.Show(ex.Message.ToString());
}
finally
{
ds.Dispose();
}
}
Any ideas??
One more thing, is it possible to lock a column for user changes? If yes then how?
Regards,
Kaushal
Last edited by kashi_rock; Feb 24th, 2010 at 02:48 AM.
-
Feb 24th, 2010, 05:40 AM
#2
Re: [Ressolved] DataGridViewComboBoxColumn SelectedIndexChanged Event
If you have solved the problem please post the solution so others may use it if needed. Thank you!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|