My first thought was "well the UltraGrid is such a huge control, there must be some property somewhere I can set to do this", something like.... myGrid.DisplayLayout.Rows[i].Header = "Row Name" or myGrid.DisplayLayout.Override.RowSelectors[i].Text = "Row Name" etc.... I spent ages looking all to no avail.
After all else failed, I resorted (as a last ditch attempt) to the infragistics knowledge base where I found this article.
Now this just talks about getting rid of the pencil, but slightly adapt it and you get the following
class RowSelectorDrawFilter : IUIElementDrawFilter
{
public RowSelectorDrawFilter(List<string> rowNames)
{
myRowNames = rowNames;
}
public DrawPhase GetPhasesToFilter(ref UIElementDrawParams drawParams)
{
// Drawing RowSelector Call DrawElement Before the Image is Drawn
if (drawParams.Element is Infragistics.Win.UltraWinGrid.RowSelectorUIElement)
return DrawPhase.BeforeDrawImage;
else
return DrawPhase.None;
}
public bool DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams)
{
// If the image isn't drawn yet, and the UIElement is a RowSelector
if (drawPhase == DrawPhase.BeforeDrawImage && drawParams.Element is Infragistics.Win.UltraWinGrid.RowSelectorUIElement)
{
// Get a handle of the row that is being drawn
UltraGridRow row = (UltraGridRow)drawParams.Element.GetContext(typeof(UltraGridRow));
drawParams.DrawString(drawParams.Element.Rect, myRowNames[row.ListIndex], false, false);
return true;
}
// Else return false, to draw as normal
return false;
}
private List<string> myRowNames = null;
}
then add the following line to the OnLoad method
myTableGrid.DrawFilter = new RowSelectorDrawFilter(myRowNames);
and providing the row names list is in the same order as the underlying table, it all just works. It is important that row.ListIndex is used to index into the rowNames array instead of row.Index, as row.Index is the display index, and if the grid is sorted, the row names will not be sorted.
Hope this helps someone else out there.
just saw your article while looking up help for rowheaders in infragistics ultragrid. Thank you. i think it is a great help. I just hope it works when i try it later today :)
ReplyDeletethanks a lot..that really helps. I have been eating my brains trying to add rowheader to winform datagrid or ultragrid.
ReplyDeleteThank you for help. I have modified your code for displaying custom images for active row.
ReplyDeleteI had been searching for this, for a while. Your article was of great help, exactly what we needed. Thank You.
ReplyDeletehi. it is the only source on the web in relation to the problem of customizing rowheader appearance. BUT! it doesn't work for me. the text is on the header but i can't increase the width of the header (only a part of the text is being shown). what is the problem?
ReplyDeleteFor those having problems with the selector width try
ReplyDeletepublic bool DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams)
{
// If the image isn't drawn yet, and the UIElement is a RowSelector
if (drawPhase == DrawPhase.BeforeDrawImage && drawParams.Element is RowSelectorUIElement)
{
// Get a handle of the row that is being drawn
UltraGridRow row = (UltraGridRow)drawParams.Element.GetContext(typeof(UltraGridRow));
row.Band.Override.RowSelectorWidth = 150; // required width for your text
Rectangle rect = drawParams.Element.Rect;
drawParams.DrawString(rect, _rowNames[row.ListIndex], false, false);
return true;
}
// Else return false, to draw as normal
return false;
}
That's great but... I wanna put an image on the top-leftcorner header (the rowselector of the headers) ... how I can to do it?
ReplyDeleteI cannot found any way to access to that zone of the ultragrid...
Many thanks for all your help.
Question to Adrian : Isn't the boolean "Wrap text" useful in that case ?
ReplyDeleteNearly 20 years later and still helpful, thanks!
ReplyDelete