简体   繁体   English

DevExpress XtraGridView 控件的问题

[英]Problem with the DevExpress XtraGridView control

I have one xtragrid control on my devxpress form .xtragrid control on my devxpress form I've created the columns of my grid at runtime when i load the form .columns of my grid at runtime when i load the form I'm developing the Field chooser for my grid view which is situated on the same form.我正在为位于同一表单上的网格视图开发字段选择器。 For that i used the repositoryItemCheckedComboBoxEdit control & in that control i added the column names which will be present in the xtragrid.为此,我使用了repositoryItemCheckedComboBoxEdit控件并在该控件中添加了将出现在 xtragrid 中的列名。

Basically i created the columns to the xtragrid with the Visible property to false.基本上,我创建了 xtragrid 的列,并将 Visible 属性设置为 false。 When user checks particular column name by using repositoryItemCheckedComboBoxEdit then i set the Visible to true & again if user unchecked the column name then again i set the visible to false.当用户使用repositoryItemCheckedComboBoxEdit 检查特定列名时,我将Visible 设置为true,如果用户取消选中列名,我再次将visible 设置为false。 & while creating column i set the width of the column. & 在创建列时,我设置了列的宽度。

Problem which i'm facing is that if user select the all fields from the repositoryItemCheckedComboBoxEdit then the grid control should show the horizontal scroll bar automatically when require.

And another problem is that with the columns is besides setting the width of the column, it is not showing the required width of that column. it shrinks that all column width.

code which i use for creating column to the xtragridview at run time is as follows -我用于在运行时为 xtragridview 创建列的代码如下 -

 public void AddGridColumn(string fieldName, string caption, int nRowWidth, RepositoryItem Item, object oCollection, string DisplayMember, string ValueMember, string format, FormatType type)
        {
            DevExpress.XtraGrid.Columns.GridColumn column = ColumnView.Columns.AddField(fieldName);
            column.Caption = caption;
            column.ColumnEdit = Item;
            column.DisplayFormat.FormatType = type;
            column.DisplayFormat.FormatString = format;
            column.VisibleIndex =  ColumnView.VisibleColumns.Count;
            column.Width = nRowWidth;
        }

code for the field chooser is as follows - I used this function for filling the items of the repositoryItemCheckedComboBoxEdit control field chooser的代码如下 - 我使用此 function 填充 repositoryItemCheckedComboBoxEdit 控件的项目

private void FieldCollection()
    {
        allFields = new ArrayList();
        columnNames = new Dictionary<string, string>();
        allFields.Clear();
        repositoryItemCheckedComboBoxEdit1.Items.Clear();
        for (int i = 0; i < gvBase.Columns.Count; i++)
        {
            allFields.Add(gvBase.Columns[i].Caption );
            if (gvBase.Columns[i].FieldName != "ContactID")
            {
                if (gvBase.Columns[i].Visible == true)
                {
                    if (gvBase.Columns[i].Caption != "Label1" && gvBase.Columns[i].Caption != "Label2" && gvBase.Columns[i].Caption != "Label3" && gvBase.Columns[i].Caption != "Label4" && gvBase.Columns[i].Caption != "Label5")
                        repositoryItemCheckedComboBoxEdit1.Items.Add(gvBase.Columns[i].Caption, CheckState.Checked);
                    if (!columnNames.ContainsKey(gvBase.Columns[i].Caption))
                        columnNames.Add(gvBase.Columns[i].Caption, gvBase.Columns[i].FieldName);
                }
                else
                {
                    if (gvBase.Columns[i].Caption != "Label1" && gvBase.Columns[i].Caption != "Label2" && gvBase.Columns[i].Caption != "Label3" && gvBase.Columns[i].Caption != "Label4" && gvBase.Columns[i].Caption != "Label5")

                        repositoryItemCheckedComboBoxEdit1.Items.Add(gvBase.Columns[i].Caption, CheckState.Unchecked);
                    if (!columnNames.ContainsKey(gvBase.Columns[i].FieldName))
                        columnNames.Add(gvBase.Columns[i].Caption, gvBase.Columns[i].FieldName);

                }
            }
        }
        cmbFieldChooser.EditValue = "";
    }

this is used for the repositoryItemCheckedComboBoxEdit control event -这用于 repositoryItemCheckedComboBoxEdit 控件事件 -

private void cmbFieldChooser_EditValueChanged(object sender, EventArgs e)
        {
            ArrayList temp = new ArrayList();
            temp.AddRange(allFields);

            string[] strFields = cmbFieldChooser.EditValue.ToString().Split(',');
            for (int i = 0; i < strFields.Length; i++)
            {
                if (temp.Contains(strFields[i].Trim()))
                    temp.Remove(strFields[i].Trim());
                if (strFields[i] != "")
                {
                    if (columnNames.ContainsKey(strFields[i].Trim()))
                    {
                        if (gvBase.Columns[columnNames[strFields[i].Trim()]].Visible == false)
                        {
                            gvBase.Columns[columnNames[strFields[i].Trim()]].Visible = true;
                            gvBase.Columns[columnNames[strFields[i].Trim()]].BestFit();

                        }
                    }
                }
            }
            if (temp.Count < 20)
            {
                for (int j = 0; j < temp.Count; j++)
                {
                    if (columnNames.ContainsKey(temp[j].ToString().Trim()))
                    {
                        gvBase.Columns[columnNames[temp[j].ToString().Trim()]].Visible = false;
                    }
                }
            }
            cmbFieldChooser.EditValue = repositoryItemCheckedComboBoxEdit1.GetCheckedItems();
            if ((cmbFieldChooser.EditValue.ToString()).Split(',').Length > 5)
            {
                gvBase.OptionsView.ColumnAutoWidth = false;
                gvBase.BestFitColumns();
                gvBase.HorzScrollVisibility = ScrollVisibility.Always;
            }
            else
            {
                gvBase.OptionsView.ColumnAutoWidth = true;
                gvBase.HorzScrollVisibility = ScrollVisibility.Never;
            }

        }

How to resolve this problem?如何解决这个问题?

thanks.谢谢。

How many columns do you have in your Grid?您的网格中有多少列?

I see you have code there to turn off the ColumnAutoWidth once you go past 5 columns (ie 6 columns or more).我看到您有代码可以在 go 超过 5 列(即 6 列或更多)后关闭 ColumnAutoWidth。 Have you debugged this condition to ensure the ColumnAutoWidth is indeed being turned off?您是否调试过这种情况以确保 ColumnAutoWidth 确实被关闭?

As per BestFitColumns Help Doc the BestFitColumns will only calculate for the first n rows as per the BestFitMaxRowCount property unless it it set to -1, could this be a cause?根据BestFitColumns 帮助文档,BestFitColumns 只会根据 BestFitMaxRowCount 属性计算前 n 行,除非它设置为 -1,这可能是原因吗?

The other thing that seems a little odd if that you are setting the EditValue of cmdFieldChooser within the cmdFieldChooser_EditValueChanged event... why so?如果您在 cmdFieldChooser_EditValueChanged 事件中设置 cmdFieldChooser 的 EditValue,另一件事似乎有点奇怪......为什么会这样?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM