我有一个xtragrid control on my devxpress form
。我创建了columns of my grid at runtime when i load the form
。我正在为我的网格视图开发Field选择器,它位于同一个窗体上。为此,我使用repositoryItemCheckedComboBoxEdit
控制&在该控件中,我添加了将出现在xtragrid中的列名。
基本上我创建了xtragrid的列,Visible属性为false。当用户使用repositoryItemCheckedComboBoxEdit检查特定列名称时,我将Visible设置为true&再次,如果用户取消选中列名称,则再次将visible设置为false。 &安培;在创建列时,我设置了列的宽度。
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 .
我在运行时用于为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;
}
<{1}}的代码如下 - 我使用此函数来填充repositoryItemCheckedComboBoxEdit控件的项目
field chooser
这用于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 = "";
}
如何解决此问题?
感谢。
答案 0 :(得分:0)
您的网格中有多少列?
我看到你有代码可以在经过5列(即6列或更多列)后关闭ColumnAutoWidth。您是否已调试此条件以确保ColumnAutoWidth确实已关闭?
根据BestFitColumns Help Doc,BestFitColumns只会根据BestFitMaxRowCount属性计算前n行,除非它设置为-1,这可能是原因吗?
如果您在cmdFieldChooser_EditValueChanged事件中设置cmdFieldChooser的EditValue,那么另一件事似乎有些奇怪...为什么会这样?