Is there a way to change the background of the last column in GridView (attached image)
I have to display different number of columns based on some properties so i can not use Data binding, I ma creating the columns in code behind and also setting the width of columns.
In order to not have the last blank column i tried to set the width of last column to *, but when i do that the horizontal scroll bar do not appear if the content in the rows is bigger than the view can display
Here is the code i am using
/// <summary>
/// Create the grid based on the list type
/// </summary>
private void InitializeGrid(csEnumListType listType)
{
switch (listType)
{
case csEnumListType.csLstAppointmentTypes:
AddColumn("Description", 250, "GridDescription");
AddColumn("Abbreviation", 100, "ColumnValue1");
AddColumn("Appointment Category", 100, "ColumnValue2", true);
break;
case csEnumListType.csLstCollectors:
case csEnumListType.csLstOperators:
AddColumn("Name", 400, "GridDescription");
AddColumn("Abbreviation", 85, "ColumnValue1", true);
break;
case csEnumListType.csLstClmStyles:
AddColumn("Description", 300, "GridDescription");
AddColumn("Abbreviation", 100, "ColumnValue1");
AddColumn("Billing Media", 85, "ColumnValue2");
AddColumn("Claim Format", 100, "ColumnValue3", true, true);
break;
default:
AddColumn("Description", 300, "GridDescription");
AddColumn("Abbreviation", 100, "ColumnValue1", true);
break;
}
}
/// <summary>
/// Add column with the header, width and binding
/// </summary>
/// <param name="col1Header"></param>
/// <param name="col1Width"></param>
private void AddColumn(string header, int width, string binding, bool isLastColumn = false, bool isClaimStyle = false)
{
GridViewDataColumn column = new GridViewDataColumn();
column.DataMemberBinding = new Binding(binding);
column.Header = header;
column.TabStopMode = GridViewTabStop.Skip;
column.Width = GridViewLength.Auto;
this.RecordsGrid.Columns.Add(column);
}
private void RecordsGrid_SourceUpdated(object sender, DataTransferEventArgs e)
{
if (RecordsGrid.Columns.Count > 0)
{
RecordsGrid.Columns[RecordsGrid.Columns.Count - 1].Width = new GridViewLength(100.123, GridViewLengthUnitType.Star);
}
}
I have to display different number of columns based on some properties so i can not use Data binding, I ma creating the columns in code behind and also setting the width of columns.
In order to not have the last blank column i tried to set the width of last column to *, but when i do that the horizontal scroll bar do not appear if the content in the rows is bigger than the view can display
Here is the code i am using
/// <summary>
/// Create the grid based on the list type
/// </summary>
private void InitializeGrid(csEnumListType listType)
{
switch (listType)
{
case csEnumListType.csLstAppointmentTypes:
AddColumn("Description", 250, "GridDescription");
AddColumn("Abbreviation", 100, "ColumnValue1");
AddColumn("Appointment Category", 100, "ColumnValue2", true);
break;
case csEnumListType.csLstCollectors:
case csEnumListType.csLstOperators:
AddColumn("Name", 400, "GridDescription");
AddColumn("Abbreviation", 85, "ColumnValue1", true);
break;
case csEnumListType.csLstClmStyles:
AddColumn("Description", 300, "GridDescription");
AddColumn("Abbreviation", 100, "ColumnValue1");
AddColumn("Billing Media", 85, "ColumnValue2");
AddColumn("Claim Format", 100, "ColumnValue3", true, true);
break;
default:
AddColumn("Description", 300, "GridDescription");
AddColumn("Abbreviation", 100, "ColumnValue1", true);
break;
}
}
/// <summary>
/// Add column with the header, width and binding
/// </summary>
/// <param name="col1Header"></param>
/// <param name="col1Width"></param>
private void AddColumn(string header, int width, string binding, bool isLastColumn = false, bool isClaimStyle = false)
{
GridViewDataColumn column = new GridViewDataColumn();
column.DataMemberBinding = new Binding(binding);
column.Header = header;
column.TabStopMode = GridViewTabStop.Skip;
column.Width = GridViewLength.Auto;
this.RecordsGrid.Columns.Add(column);
}
private void RecordsGrid_SourceUpdated(object sender, DataTransferEventArgs e)
{
if (RecordsGrid.Columns.Count > 0)
{
RecordsGrid.Columns[RecordsGrid.Columns.Count - 1].Width = new GridViewLength(100.123, GridViewLengthUnitType.Star);
}
}