I am having a problem with my datagridview. I have a small table that
has two columns. The first column is bound to my dataset. The second
column is a combobox. I add items to the combobox based on the
information that I get from a text file. I then try to set the value of
the combobox to a specific value based on the first column.
The code is working to set the value, but it will not refresh and
display the selected value on the screen unless I move to a previous
tab and then back.
private void tabPage2_Enter(object sender, EventArgs e)
{
if (!cc.Validate_RequiredField(txtFilePath)
|| !cc.Validate_RequiredField(cboDelimiter))
{
tbcWizardPages.SelectedIndex = 0;
return;
}
btnPrevious.Enabled = true;
btnNext.Enabled = true;
txtImportTable.Text = msTable;
FillTableColumns();
FillImportColumns();
tabPage2.Refresh();
}
private void FillImportColumns()
{
string sColumn = "";
int iFields = 0, iIndex = 0;
this.ImportColumns.Items.Clear();
iFields = GetFileFieldCount();
if (chkHeaderRows.Checked == true)
{
StreamReader reader = new
StreamReader(txtFilePath.Text);
string sLine;
string sDelimiter =
cboDelimiter.Text.Substring((cboDelimiter.Text.Ind exOf("{") + 1), 1);
sLine = reader.ReadLine();
iIndex = sLine.IndexOf(sDelimiter);
for (int i = 0; i < iFields; i++)
{
if (iIndex >= 0)
{
this.ImportColumns.Items.Add(sLine.Substring(0,
iIndex));
}
else
{
this.ImportColumns.Items.Add(sLine);
}
sLine = sLine.Substring(iIndex+1);
iIndex = sLine.IndexOf(sDelimiter);
}
//Now try to match up column names
for (int i = 0; i < dataSet2.ImportHeaders.Rows.Count;
i++)
{
grdImportTable.Rows[i].Cells[1].Value =
"<default>";
sColumn =
grdImportTable.Rows[i].Cells[0].Value.ToString();
foreach( string str in this.ImportColumns.Items)
{
if (sColumn == str)
grdImportTable.Rows[i].Cells[1].Value =
str;
}
}
}
else
{
for (int i = 0; i < dataSet2.ImportHeaders.Rows.Count;
i++)
{
//We need to only add these for the number of
columns that are in the file
//the rest need to be set to default.
if (i < iFields)
{
this.ImportColumns.Items.Add("Col" +
Convert.ToString(i + 1));
grdImportTable.Rows[i].Cells[1].Value = "Col" +
Convert.ToString(i + 1);
}
else
{
grdImportTable.Rows[i].Cells[1].Value =
"<default>";
}
}
}
this.ImportColumns.Items.Add("<default>");
}
Like I said, the value is set for the combobox to the correct item in
the list, but will not display. If I click on a previous tab and then
toggle back, the value will display. I have tried refreshing from every
possible object and it won't work. Any suggestions? Is it possible that
the edited cell value has not committed? If so, how do I make that
happen. I have tried EndEdit, etc...
Thanks,
Jennifer