Otis wrote:
Do you use adapter or selfservicing?
Self-servicing:
private void searchButton_Click(object sender, EventArgs e)
{
// First DataGrid, no table style, DataSource = collection that I dragged in
// from the designer
IPredicateExpression selectFilter = new PredicateExpression();
string searchValue = this.searchValueTextBox.Text;
selectFilter.Add(PredicateFactory.Like(HeadwordFieldIndex.TonelessRoman, searchValue));
this.phrasesHeadwordCollection.GetMulti(selectFilter);
// Second DataGrid, I created the collection in code
// and I created a table style in designer
// with one text box column bound to the first field in the collection
HeadwordCollection charactersHeadwordCollection = new HeadwordCollection();
this.charactersDataGrid.DataSource = charactersHeadwordCollection;
this.charactersHeadwordCollection.GetMulti(selectFilter);
}
Here is the code for the table style:
//
// dataGridTableStyle2
//
this.dataGridTableStyle2.DataGrid = this.charactersDataGrid;
this.dataGridTableStyle2.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {
this.dataGridTextBoxColumn2});
this.dataGridTableStyle2.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGridTableStyle2.MappingName = "";
//
// dataGridTextBoxColumn2
//
this.dataGridTextBoxColumn2.Format = "";
this.dataGridTextBoxColumn2.FormatInfo = null;
this.dataGridTextBoxColumn2.HeaderText = "Pinyin";
this.dataGridTextBoxColumn2.MappingName = "Pinyin";
this.dataGridTextBoxColumn2.Width = 75;
At runtime, both data grids show all the columns in the collection. The first grid shows all the columns when the form opens, and the second grid shows all the columns after the searchButton_Click method runs.