Hi, I have a datagridview in the main form. By clicking on a particular column of datagridview, it will open the sub form or ownedform(dynamically created). The owned form have a listbox and an OK button. When The user selects an item from listbox and click OK then selected text needs to be appear on the datagridview cell. But when i click OK i couldn't get the result. I am not receiving any error neither.Here's the code
NOTE: If use Textbox instead of listbox, i am able to pass the value to datagridview. I just don't know the way to handle listbox to pass value.
CODE FOR DYNAMICALLY CREATING OWNED FORM & ADDING CONTROLS
private List
BUTTON CLICK EVENT HANDLER - NOT WORKING (LISTBOX)
private void dbtn_Click_SIGTB(object sender, EventArgs e)
{
int rowidx = dataGridView3.CurrentCell.RowIndex;
int colidx = dataGridView3.CurrentCell.ColumnIndex;
foreach(ListBox lb in inputlistboxes)
{
string selected = lb.GetItemText(lb.SelectedItem);
dataGridView2.Rows[rowidx].Cells[colidx].Value = selected;
}
foreach (Form frm in ownform)
frm.Close();
}
BUTTON EVENT HANDLER - WORKING (TEXTBOX)
private void dbtn_Click_VARTB(object sender, EventArgs e)
{
int rowidx = dataGridView2.CurrentCell.RowIndex;
int colidx = dataGridView2.CurrentCell.ColumnIndex;
foreach (TextBox txt in inputTextBoxes)
dataGridView2.Rows[rowidx].Cells[colidx].Value = txt.Text;
foreach (Form frm in ownform)
frm.Close();
}
DATAGRIDVIEW CELL CONTENT CLICK
private void dataGridView3_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView3.CurrentCell.ColumnIndex.Equals(3))
{
ShowMyOwnedForm_SIGTB();
}
}
What I have tried:
private void dbtn_Click_SIGTB(object sender, EventArgs e)
{
int rowidx = dataGridView3.CurrentCell.RowIndex;
int colidx = dataGridView3.CurrentCell.ColumnIndex;
foreach(ListBox lb in inputlistboxes)
{
string selected = lb.GetItemText(lb.SelectedItem);
dataGridView2.Rows[rowidx].Cells[colidx].Value = selected;
}
foreach (Form frm in ownform)
frm.Close();
}