Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating Datagrid Column

Status
Not open for further replies.

dpanattoni

IS-IT--Management
Jan 29, 2002
76
US
Which event is the appropriate event to set the value of a column?

I have created an ODBC query that fills a grid. But one of the fields (columns) selected is a code. Based on the value of this code, I want to set one of the other datagrid columns equal to an appropriate text message.

Thanks,
 
It needs to happen when the grid is being built.
 
You don't mention the underlying datasource for your grid - dataset, dataview, etc.

Let's assume it's a dataset.
After populating the dataset and before setting the datasource for the grid, you might course the dataset and make the necessary adjustments, then set the datasource for the grid.
Something like this:


// fill the dataset using a dataAdapter:
daCustomer.Fill(dsCustomer.Table1);

// Course the dataset to make changes
// assume that the column containing the code is named 'code' and the message column is named 'Notation' ...

foreach(DataRow dr in dsCustomer.Table1.Rows)
{
if (dr["code"].ToString.CompareTo("Secret")==0)
{ dr["Notation"] = "Eyes Only!"; }
}

// Set datagrid datasource
dgCustomerDisplay.DataSource = dsCustomer.Table1;

I can't be certain all the spelling is correct without the help of intellisense, but that should get you started.
Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top