TableStyle

Posts   
 
    
Rhywun avatar
Rhywun
User
Posts: 44
Joined: 05-Jan-2005
# Posted on: 24-Jan-2005 03:52:16   

I'm trying to create a custom TableStyle for my Windows Forms DataGrid. I created a new TableStyle, used "" for the MappingName like it says in another thread, and added just one column to the TableStyle. But when I run the program I get all the fields from the collection instead of my custom TableStyle. I tried various approaches including setting the DataSource at design time and setting it in code, with the same results. So how exactly do I bind the collection to a DataGrid and show custom columns?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 24-Jan-2005 10:26:25   

Do you use adapter or selfservicing? Could you paste some code please, which you've tried and which failed so I can try to reproduce it here?

Frans Bouma | Lead developer LLBLGen Pro
Rhywun avatar
Rhywun
User
Posts: 44
Joined: 05-Jan-2005
# Posted on: 24-Jan-2005 14:37:43   

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.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 24-Jan-2005 16:28:27   

Ok, I'll check it out.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 24-Jan-2005 18:29:41   

Set the table mapping style's MappingName to "HeadwordCollection".

Selfservicing works differently in this than adapter. In adapter I made the mistake of not returning the listname in ITypedList.GetListName(), as it should be returned by generated code, but this was omitted. The result was that mentioning a name for MappingName would not work, so a "" had to be mentioned. Fixing this was not possible as that would break all adapter binding code already implemented by customers.

Frans Bouma | Lead developer LLBLGen Pro
Rhywun avatar
Rhywun
User
Posts: 44
Joined: 05-Jan-2005
# Posted on: 25-Jan-2005 02:40:58   

Otis wrote:

Set the table mapping style's MappingName to "HeadwordCollection".

Works great - especially with the drag-n-drop collection. Thanks!