I have a C# Win ultraGrid with several groups and several users under each group.
I have a name (hidden) an alias. I made it so when you right click it, there's an option to reset the alias to the name by:
this.ultraGridUsers.Selected.Rows[0].Cells["Alias"].Value
= this.ultraGridUsers.Selected.Rows[0].Cells["UnitID"].Text
Is there a way to reset the whole grid? I tried:
this.ultraGridUsers.Rows[0].Cells["Alias"].Value = this.ultraGridUsers.Rows[0].Cells["UnitID"].Text;
but it's giving me a 'key' error.
Are your users in the second band? grid.Rows are only the first band rows.
Why do you use Value and then Text?
What do you mean by "reset the whole grid"?
BTW, you can avoid all those "Cells[]" statements (that affect performance), and use the data object itself. Any row has a ListObject property that you can cast and change anything you want in it, like:
var dataObject = row.ListObject as MyDataObject;
dataObject.Alias = dataObject.UnitID;
However, if you still want to play with Cells[], you can use the row.GetCellValue(columnKey) when you want to get the value, which skips creating the cell object.
All the users are in the second band, yes-- band[1]. The group is band[0].
I'm using the .value & .text to set the value of the "Alias" value (value) to take in whatever is in the "UnitID" field (text), it seems to work.
The true identity of each cell is the "UnitID." You can give it an alias, "Alias." I made an event listener when you click something, it will erase the "Alias" and default to the "UnitID" (unchangeable).
That's what the above code does. Let's say if I have several that are aliased and want to reset the whole list. is there a way to do that?
UnitID: p111 Alias: BobUnitID: p1121 Alias: RobUnitID: p1234 Alias: Job
When I right-click "bob" and click "reset alias" it will rename the Alias to the UnitID: P111
I was wondering if there was a way to do it for all in one click.
That's only if it's selected. I want to do it for all UserIDs and Aliases that exist in that grid.
I tried removing the 'Selected' in those statements but it didn't work.
It doesn't work since the Rows property in the grid are only the first band rows, not the users rows. In order to get all second band rows use:
grid.Rows.GetRowEnumerator(GridRowType.DataRow, grid.DisplayLayout.Bands[1], null)
I'm not familiar with Enumerators at all, so I looked up some Infragistics docs and came up with this:
UltraGridBand band = this.ultraGridUsers.DisplayLayout.Bands[1];
IEnumerable enumerator = band.GetRowEnumerator(rowTypes);
foreach (UltraGridRow row in enumerator)
{
row.Cells["Alias"].Value = row.Cells["UnitID"].Text;
}
It seems promising, the only thing is the IEnumerable part, throwing an error:
Error 3 Using the generic type 'System.Collections.Generic.IEnumerable<T>' requires '1' type arguments.
Thanks for your continued help.
Add in the file "using area":
using System.Collections;
Doh, I thought "using System.Collections.Generic;" covered it.
Thanks for all your help.