Problem with datagrid

D

David

Hi all,

I am using C#, .NET 1.1 Windows Forms.

I am populating a datagrid from a webservice. This works brilliantly.

When the grid is populated, I click a cell and then transfer the row in the
grid to the textboxes. This sort of works... The text boxes fill with data,
but the data is from a different row. :-(

Here is my code...

private void FillMyLinksGrid()
{

if (tabControl1.SelectedIndex == 1)
{

// TODO: Cache data locally so that this does not need to be called each
time.
FOCUSLinks.Sites sites = new FOCUSLinks.Sites();
DataSet MyLinks =
sites.GetLinks(ConfigurationSettings.AppSettings["UserName"],
ConfigurationSettings.AppSettings["Password"]);

try
{
if (!ViewAllCheckBox.Checked)
{
MyLinks.Tables[0].DefaultView.RowFilter = "SiteID = " +
SiteListBox.SelectedValue;
MyLinksDataGrid.DataSource = MyLinks.Tables[0].DefaultView;
}
else
{
MyLinksDataGrid.DataSource = MyLinks.Tables[0];
}

}
catch(Exception ex)
{
//MessageBox.Show(ex.Message);
}


}
}

private void MyLinksDataGrid_CurrentCellChanged(object sender,
System.EventArgs e)
{
FillBoxesFromGrid();
}

private void FillBoxesFromGrid()
{
EditLinkURLTextBox.Enabled = true;
EditLinkTextTextBox.Enabled = true;
EditLinkDescTextBox.Enabled = true;
EditEmailTextBox.Enabled = true;
EditReciprocalLinkTextBox.Enabled = true;
EditLinkEnabledCheckBox.Enabled = true;
UpdateButton.Enabled = true;

try
{
int DataIndex = MyLinksDataGrid.CurrentRowIndex;

DataView DV = (DataView)MyLinksDataGrid.DataSource;
//DataRow DR = DV.Table.DefaultView.Table.Rows[DataIndex];
DataRow[] DR = DV.Table.Select();
EditLinkURLTextBox.Text = DR[DataIndex]["LinkURL"].ToString();
EditLinkTextTextBox.Text = DR[DataIndex]["LinkText"].ToString();
EditLinkDescTextBox.Text = DR[DataIndex]["LinkDescription"].ToString();
EditEmailTextBox.Text = DR[DataIndex]["Email"].ToString();
EditReciprocalLinkTextBox.Text =
DR[DataIndex]["ReciprocalLink"].ToString();
if (DR[DataIndex]["Enabled"].ToString() == "1")
{
EditLinkEnabledCheckBox.Checked = true;
}
else
{
EditLinkEnabledCheckBox.Checked = false;
}

}
catch(Exception ex)
{

}

}



Any ideas what I am doing wrong?

Thanks.


Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top