This is a migrated thread and some comments may be shown as answers.

Datagrid ComboBoxes - Programmatically vs. XAML

1 Answer 80 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 22 Mar 2011, 01:38 PM

Thanks in advance for the thoughts.  Currently I have a RadGrid with a fair amount of comboboxes.  In order to ensure that the comboboxes have been populated prior to drawing the grid, I have opted to create the columns programmatically after a chain of DDS HasLoaded events.  When they iterate to 9, I call a programmatic build of the Grid.  For lack of a better phrase, is there a better approach to incorporate a more robust XAML / MVVM approach?  Thanks for the insight.

private void CheckIfCompleted()
        {
            callCount++;
            Debug.WriteLine(callCount);
            if (callCount == 9)
                OnAsyncDone(new EventArgs());
        }
protected virtual void OnAsyncDone(EventArgs e)
        {
            if (AsyncDone != null)
            {
                AsyncDone(this, e);
            }
  
            buildChildGrid();
        }
private void buildChildGrid()
        {
  
            var cboColumn = new GridViewComboBoxColumn();
            var cboColumn1 = new GridViewComboBoxColumn();
            var cboColumn2 = new GridViewComboBoxColumn();
            var cboColumn3 = new GridViewComboBoxColumn();
            var txtColumn = new GridViewDataColumn();
            var txtColumn2 = new GridViewDataColumn();
            var txtColumn3 = new GridViewDataColumn();
            var txtColumn4 = new GridViewDataColumn();
            var chkColumn1 = new GridViewCheckBoxColumn();
  
            {
                txtColumn.UniqueName = "unitQtyColumn";
  
                txtColumn.DataMemberBinding = new Binding("unitQty");
                txtColumn.DataMemberBinding.Mode = BindingMode.TwoWay;
                txtColumn.Header = "Quantity";
                txtColumn.SortMemberPath = "unitQty";
                txtColumn.Width = new GridViewLength(100, GridViewLengthUnitType.Pixel);
                txtColumn.TextAlignment = TextAlignment.Center;
                 
            }
  
             
  
            {
                cboColumn.ItemsSource = qryOriginVarietalDomainDataSource.Data;
                cboColumn.DisplayMemberPath = "oriVar";
                cboColumn.SelectedValueMemberPath = "varietalID";
                cboColumn.UniqueName = "cboVarietalIDColumn";
                cboColumn.Header = "Origin - Varietal";
                cboColumn.DataMemberBinding = new Binding("varietalID");
                cboColumn.DataMemberBinding.Mode = BindingMode.TwoWay;
                cboColumn.SortMemberPath = "varietalID";
                cboColumn.Width = new GridViewLength(1, GridViewLengthUnitType.SizeToCells);
  
            }
  
            {
                cboColumn1.ItemsSource = tblGradeDomainDataSource.Data;
                cboColumn1.DisplayMemberPath = "gradeName";
                cboColumn1.SelectedValueMemberPath = "gradeID";
                cboColumn1.UniqueName = "gradeIDColumn";
                cboColumn1.Header = "Grade";
                cboColumn1.DataMemberBinding = new Binding("gradeID");
                cboColumn1.DataMemberBinding.Mode = BindingMode.TwoWay;
                cboColumn1.SortMemberPath = "gradeID";
                cboColumn1.Width = new GridViewLength(1, GridViewLengthUnitType.SizeToCells);
  
            }
  
            {
                txtColumn2.UniqueName = "unitPriceColumn";
                txtColumn2.DataMemberBinding = new Binding("unitPrice");
                txtColumn2.DataMemberBinding.Converter = new StringFormatValueConverter("{0:$##0.0000}");
                //txtColumn2.DataMemberBinding.Converter = new StringFormatValueConverter("{0:C}");
                txtColumn2.DataMemberBinding.Mode = BindingMode.TwoWay;
                txtColumn2.Header = "Unit Price";
                txtColumn2.SortMemberPath = "unitPrice";
                txtColumn2.Width = new GridViewLength(125, GridViewLengthUnitType.Pixel);
                txtColumn2.TextAlignment = TextAlignment.Center;
            }
  
            {
                txtColumn3.UniqueName = "transDescColumn";
                txtColumn3.DataMemberBinding = new Binding("transDesc");
                txtColumn3.DataMemberBinding.Mode = BindingMode.TwoWay;
                txtColumn3.Header = "Chop - Mark";
                txtColumn3.SortMemberPath = "transDesc";
                txtColumn3.Width = new GridViewLength(1, GridViewLengthUnitType.Star);
                txtColumn3.MinWidth = 100;
            }
  
            {
                cboColumn2.ItemsSource = tblLocationDomainDataSource.Data;
                cboColumn2.DisplayMemberPath = "location";
                cboColumn2.SelectedValueMemberPath = "locationID";
                cboColumn2.UniqueName = "cboLocationColumn";
                cboColumn2.Header = "Point of Purchase";
                cboColumn2.DataMemberBinding = new Binding("poLocID");
                cboColumn2.DataMemberBinding.Mode = BindingMode.TwoWay;
                cboColumn2.SortMemberPath = "poLocID";
                cboColumn2.Width = new GridViewLength(1, GridViewLengthUnitType.SizeToCells);
            }
  
            {
                chkColumn1.UniqueName = "chkCertColumn";
                chkColumn1.Header = "Cert";
                chkColumn1.DataMemberBinding = new Binding("isCert");
                chkColumn1.DataMemberBinding.Mode = BindingMode.TwoWay;
                chkColumn1.SortMemberPath = "isCert";
                chkColumn1.Width = new GridViewLength(30, GridViewLengthUnitType.Pixel);
                chkColumn1.TextAlignment = TextAlignment.Center;
            }
  
            {
                List<string> dropDownLoad_ArabicaRobusta = new List<string>();
                dropDownLoad_ArabicaRobusta.Add("Arabica");
                dropDownLoad_ArabicaRobusta.Add("Robusta");
                cboColumn3.ItemsSource = dropDownLoad_ArabicaRobusta;
                cboColumn3.UniqueName = "cboArabicaRobustaColumn";
                cboColumn3.Header = "Species";
                cboColumn3.DataMemberBinding = new Binding("robArab");
                cboColumn3.DataMemberBinding.Mode = BindingMode.TwoWay;
                cboColumn3.SortMemberPath = "robArab";
                cboColumn3.Width = new GridViewLength(1, GridViewLengthUnitType.SizeToCells);
            }
  
            {
                dg_tblPOLines.Columns.Add(txtColumn);
                dg_tblPOLines.Columns.Add(cboColumn);
                dg_tblPOLines.Columns.Add(cboColumn3);
                dg_tblPOLines.Columns.Add(cboColumn1);
                dg_tblPOLines.Columns.Add(chkColumn1);
                dg_tblPOLines.Columns.Add(txtColumn2);
                dg_tblPOLines.Columns.Add(txtColumn3);
                dg_tblPOLines.Columns.Add(cboColumn2);
            }

1 Answer, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 22 Mar 2011, 01:55 PM
Hi Mark,

I think I know what your problem is. I had the same one.

I had several combo-boxes that had to be loaded from each a RadDomainDataSource. When the page was initially loaded, I told all domain data sources to start loading. Now the problem was that I did not know when all of the data will come back to the client. So here is what I did.

I created a DispatcherTimer that would check whether all of the data has arrived on the client. For every domain data source I created a local boolean field that would indicate whether it has been loaded or not. I attached to the LoadedData of every domain data source and when this event happended I raised the respective boolean flag. On each timer tick, if all of the flags are true -- this meant that all of the data has arrived on the client and I could continue with my work -- for example show something that was invisible or load another set of data.

A similar approach you can see in this online demo. Examine how the dispatcher timers check whether the two combo boxes have been loaded prior to loading the main grid.

I hope this helps.

Regards,
Ross
the Telerik team
Tags
General Discussions
Asked by
Mark
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or