DataGridViewComboBox Column - Binding using FieldAlias that retrieves DataTable

Posts   
 
    
qzcreative
User
Posts: 13
Joined: 20-Feb-2009
# Posted on: 23-Feb-2009 15:16:04   

**Technology: ** MSSQL 2005 LLBLGEN Pro v2.6 - DataAdapter C#

Tables and relations: Customer - 1:m -> Statement

I have a DataGrid that is populated using a TypedList. I want to add a column that contains a combobox. because of the way the data is structured I have chosen to use the following to get the values for the combobox, but then I can't seem to bind it. I use the ApplyGridstyles method to set the grid up and then I set the datasource seperately somewhere else in the code. All is well until I try and populate the grid with the data.

To setup the grid I use:


                   grdReturnedMailCustomers.ReadOnly = false;

                    EntityField2 contactAddressField = new EntityField2("CustomerFullAddress",
                            new DbFunctionCall("[dbo].[cusif_GetFullAddressFromCrm]", new object[] { ContactAdrsFields.AddressId, ",", 1 }));



                    grid.AddNewColumn<DataGridViewTextBoxColumn>("CustomerID", CustomerFields.CustomerId).Visible = false;
                    grid.AddNewColumn<DataGridViewTextBoxColumn>("AccountNo", CustomerFields.AccountNo).Visible = true;
                    grid.AddNewColumn<DataGridViewTextBoxColumn>("CustomerFullName", ContactEntity.GetContactFullNameEntityField().SetFieldAlias("CustomerFullName")).AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                    grid.AddNewColumn<DataGridViewTextBoxColumn>("CustomerFullAddress", contactAddressField).Visible = true;
                    grid.AddNewColumn<DataGridViewTextBoxColumn>("ReturnedReason", ReturnedMailFields.ReturnedMail).Visible = true;
                    grid.AddNewColumn<DataGridViewTextBoxColumn>("ReturnedDate", ReturnedMailItemFields.ReturnedDate, "d").Visible = true;

I have to use a db function to retrieve a concatenated address string (long story - works perfectly).

I then try the same method to retrieve a datatable for the statementdate in the following way:


//Get datatable using customerid
                    EntityField2 contactAddressField = new EntityField2("StatementId",
                            new DbFunctionCall("[dbo].[cusif_promisf_GetStatementsByCustomerId]", new object[] { CustomerFields.CustomerId }));

and try and add the column to the grid:


                    DataGridViewComboBoxColumn colStmtDate = DataGridViewComboBoxColumn();
                    colStmtDate.DataPropertyName = "StatementId";
                    colStmtDate.DataSource = statementField;
                    colStmtDate.DisplayMember = StatementFields.StmtDate.Name;
                    colStmtDate.ValueMember = StatementFields.StatementId.Name;
                    colStmtDate.ReadOnly = false;
                    grdReturnedMailCustomers.Columns.Add(colStmtDate);

By default I would like to select the combo index 1 (second value) for each row requried by business rules (to select the 2nd last statement).

What am i missing?! please let me know if you need anymore info...

qzcreative
User
Posts: 13
Joined: 20-Feb-2009
# Posted on: 24-Feb-2009 08:23:30   

So basically I want to populate a dropdown within a cell in a datagrid... but the existing patterns of the application doesn't seem to allow it, so I'd be pretty happy to get it working, cause I've wasted so much time already. If anyone has any ideas please let me know.

I have tried creating a seperate datatable to be the datasource for that combobox, but now how the heck would I set that??

I've done the follwing in the applygridstyles eventhandler method:

                
DataGridViewComboBoxColumn colStmtDate = grid.AddNewColumn<DataGridViewComboBoxColumn>("Statement Date", StatementFields.StatementId, "", 100);//new DataGridViewComboBoxColumn();
                    colStmtDate.DataPropertyName = null;
                    colStmtDate.DisplayMember = StatementFields.StmtDate.Name;
                    colStmtDate.ValueMember = StatementFields.StatementId.Name;
                    colStmtDate.DataSource = statements; //datatable

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 24-Feb-2009 08:35:26   

colStmtDate.DataSource = statementField;

What's "statementField"?

qzcreative
User
Posts: 13
Joined: 20-Feb-2009
# Posted on: 24-Feb-2009 08:46:59   

qzcreative wrote:

**Technology: ** MSSQL 2005 LLBLGEN Pro v2.6 - DataAdapter C#

Tables and relations: Customer - 1:m -> Statement

I have a DataGrid that is populated using a TypedList. I want to add a column that contains a combobox. because of the way the data is structured I have chosen to use the following to get the values for the combobox, but then I can't seem to bind it. I use the ApplyGridstyles method to set the grid up and then I set the datasource seperately somewhere else in the code. All is well until I try and populate the grid with the data.

To setup the grid I use:


                    EntityField2 statementField = new EntityField2("StatementId",
                            new DbFunctionCall("[dbo].[promisf_GetStatementsByCustomerId]", new object[] { CustomerFields.CustomerId }));



                    grid.AddNewColumn<DataGridViewTextBoxColumn>("CustomerID", CustomerFields.CustomerId).Visible = false;
                    grid.AddNewColumn<DataGridViewTextBoxColumn>("AccountNo", CustomerFields.AccountNo).Visible = true;
                    grid.AddNewColumn<DataGridViewTextBoxColumn>("CustomerFullName", ContactEntity.GetContactFullNameEntityField().SetFieldAlias("CustomerFullName")).AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                    grid.AddNewColumn<DataGridViewTextBoxColumn>("CustomerFullAddress", contactAddressField).Visible = true;
                    grid.AddNewColumn<DataGridViewTextBoxColumn>("ReturnedReason", ReturnedMailFields.ReturnedMail).Visible = true;
                    grid.AddNewColumn<DataGridViewTextBoxColumn>("ReturnedDate", ReturnedMailItemFields.ReturnedDate, "d").Visible = true;

I have to use a db function to retrieve a concatenated address string (long story - works perfectly).

I then try the same method to retrieve a datatable for the statementdate in the following way:


//Get datatable using customerid
                    EntityField2 contactAddressField = new EntityField2("StatementId",
                            new DbFunctionCall("[dbo].[cusif_promisf_GetStatementsByCustomerId]", new object[] { CustomerFields.CustomerId }));

and try and add the column to the grid:


                    DataGridViewComboBoxColumn colStmtDate = DataGridViewComboBoxColumn();
                    colStmtDate.DataPropertyName = "StatementId";
                    colStmtDate.DataSource = statementField;
                    colStmtDate.DisplayMember = StatementFields.StmtDate.Name;
                    colStmtDate.ValueMember = StatementFields.StatementId.Name;
                    colStmtDate.ReadOnly = false;
                    grdReturnedMailCustomers.Columns.Add(colStmtDate);

By default I would like to select the combo index 1 (second value) for each row requried by business rules (to select the 2nd last statement).

What am i missing?! please let me know if you need anymore info...

Corrected code above... statementField is an entityfield. I thought I could try a similiar wayof getting a datatable from the db by using a function (it doesn't work though) it's very likely that I'm thinking about this all wrong. I'm quite new to llblGen ...

Unfortunately due to the architecture and what I am trying to achieve I cannot bind the value in the combo box to anything, cause that is the reason for displaying the data.. i want to display the data for the user to check and then use if to add another entity (ReturnedMailItem which uses statementId, StmtDate, customerId, ReturnedDate (value from UI).

Please let me know if I should clarify more...I can see that it might be quite confusing...

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 24-Feb-2009 08:52:29   

You should use another LLBLGenProDataSource to load the combo box.

Please check the ASP.NET 2.0 databinding example in the download section of our website. Check the Grid in the Products page, Editing a row will show a dropdownList for the Category.

qzcreative
User
Posts: 13
Joined: 20-Feb-2009
# Posted on: 24-Feb-2009 10:34:48   

Thanks. I've downloaded and busy checking. I'm having issues with SD.LLBLGen.Pro.Examples reference, but have created another thread for that cause it's a seperate issue.

qzcreative
User
Posts: 13
Joined: 20-Feb-2009
# Posted on: 24-Feb-2009 11:36:38   

Walaa wrote:

You should use another LLBLGenProDataSource to load the combo box.

Please check the ASP.NET 2.0 databinding example in the download section of our website. Check the Grid in the Products page, Editing a row will show a dropdownList for the Category.

Thank you. That however is quite different from what I am trying to achieve. I can explain it in much simpler terms ... each row has a few columns with data from various entities. One of the columns is CustomerId. I need to use that customerId to populate a list of statementdates in the comboxbox in the combobox column. So the list will always be different depending on the customerID. The data doesn't need to be bound both ways. I just want to display it and then I'll check the value in code which I will use to add a different entity (together with other values).

I cannot preselect a from the combox as it is not stored in the database yet, but I do want to select the 2nd index value (index 1) as default.

So my problem is that I set a datatable as the datasource for the datagridview, but I cannot manage to populate the combobox in the combobox column using the customerid column(cell) value. Does that make sense?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 25-Feb-2009 09:34:37   

Yes it makes sense.

I think you should try handling some grid event, eg. RowDataBound to catch the customerId value of each row, and based on that fecth the data for the combobox.

qzcreative
User
Posts: 13
Joined: 20-Feb-2009
# Posted on: 25-Feb-2009 11:17:06   

Walaa wrote:

Yes it makes sense.

I think you should try handling some grid event, eg. RowDataBound to catch the customerId value of each row, and based on that fecth the data for the combobox.

Thank you. All sorted simple_smile