Hi, I upgraded to Infragistics 14.2 and I am trying to initialize a column as a dropdown whose value is coming from a data table. What is the equivalent property of valuelist in the new version of webdatagrid GridField column?Please help to convert the below code .
After I upgraded I changed the UltraGridColum to GridField. Please help . Thank you!
public void InitColumnDropDown(UltraGridColumn col, DataTable dt, string valueColumn, string displayColumn,
object emptyValue, string emptyDisplayValue)
{
if (col == null) throw new ArgumentNullException();
if (dt == null || dt.Columns.Count <= 0) throw new ArgumentNullException();
if (valueColumn == null || valueColumn.Trim().Length <= 0 ||
displayColumn == null || displayColumn.Trim().Length <= 0)
throw new ArgumentNullException();
col.ValueList.Reset();
if (emptyValue != null && emptyDisplayValue != null)
col.ValueList.ValueListItems.Add(emptyValue, emptyDisplayValue);
int id = dt.Columns.IndexOf(valueColumn);
int name = dt.Columns.IndexOf(displayColumn);
foreach (DataRow dr in dt.Rows)
col.ValueList.ValueListItems.Add(dr[id], dr[name].ToString());
}
col.ValueList.Style.Font.Name = "Microsoft Sans Serif";
col.ValueList.Style.Font.Size = FontUnit.XXSmall;
col.Type = ColumnType.DropDownList;
Hello,
Thank you for contacting us.
In order to achieve the same behaviour with WebDataGrid, you should use DropDownProvider for EditorProvider of the specified colum (sample - http://www.infragistics.com/samples/aspnet/data-grid/dropdown-editors). In this case the desired function would look like this:
I am attaching a working sample of the described scenario.
Looking forward to hearing from you.
Hi Tihomir, Thank you much for your reply! This will be helpful for my other scenarios. They are calling this method(InitColumnDropdown) from the ultrawebgrid_initializelayout mathod as below: This is what I am trying to convert using webdatagrid. And also my grid display does not need to show the dropdown in the column. Could you please help on this. Thank you much!
private void Ultrawebgrid_InitializeLayout(object sender, LayoutEventArgs e)
e.Layout.AllowColSizingDefault = AllowSizing.Free;
e.Layout.AllowColumnMovingDefault = AllowColumnMoving.None;
e.Layout.RowStyleDefault.BackColor = Color.White;
e.Layout.RowAlternateStyleDefault.BackColor = Color.Lavender;
string[] cols are defined here
string[] captions are defined here
int[] width = { 50, 50, 50, 80, 1, 80, 1, 80, 1 };
bool[] hidden = { false, false, false, false, true, false, true, false, true };
HorizontalAlign[] align = {HorizontalAlign.Left, HorizontalAlign.Left, HorizontalAlign.Left,
HorizontalAlign.Left, HorizontalAlign.Left, HorizontalAlign.Left,
HorizontalAlign.Left, HorizontalAlign.Left, HorizontalAlign.Left};
UltraGridColumn col;
if (ultraWebGridHelper == null) ultraWebGridHelper = new UltraWebGridHelper();
for (int i = 0; i < cols.Length; i++)
col = e.Layout.Bands[0].Columns.FromKey(cols[i]);
if (col == null) continue;
col.Move(i);
col.AllowUpdate = AllowUpdate.No;
col.HeaderText = captions[i];
col.Width = new Unit(width[i] + "px");
col.Hidden = hidden[i];
col.CellStyle.HorizontalAlign = align[i];
if (cols[i] == "ID")
using (DataTable dt = boLkup.GetValidID's())
ultraWebGridHelper.InitColumnDropDown(col, dt, "id", "name");
ultraWebGridHelper.HideExtraColumns(e.Layout.Grid, 0, cols);
// Is there an InitializeLayout event to trigger?
if (InitializeLayout != null) InitializeLayout(this, e);
UltraWebGrid and WebDataGrid have different architectures. Although the event InitializeLayout is not available in the WebDataGrid, the desired behavior could be achieved with WebDataGrid.
Here are some resources which would help you converting your UltraWebGrid code into WebGrid code:
Dynamically adding columns - http://www.infragistics.com/samples/aspnet/data-grid/dynamic-columns
Styling guide - http://www.infragistics.com/community/blogs/engineering/archive/2010/08/25/webdatagrid-css-styling-guide.aspx
Behaviours - http://help.infragistics.com/Help/Doc/ASPNET/2014.2/CLR4.0/html/WebDataGrid_Behaviors.html
Column Resizing - http://help.infragistics.com/doc/ASPNET/2014.2/CLR4.0/?page=WebDataGrid_Column_Resizing.html
Please let me know if you need any further assistance.
I am glad you find my suggestions helpful.