I try ,,
foreach (GridViewCellInfo cellInfo in this.radGridView1.SelectedCells)
{
textBox1.Text = cellInfo.Item.ToString();
}
but don't get the value.
There is lot's of references to GridViewCellInfo Value but my GridViewCellInfo only offers Column,Equals,GetHashCode,GetType,Item,ToString
Help !
Thanks
Jim
6 Answers, 1 is accepted
The cellInfo below seems come back as type Customer ( i.e. the whole row ).
And I can access the columns i.e
cu.ContactTitle
below.But
cu.ContactTitle
wasn't the selected cell so how can I get/know the selected cell.foreach (GridViewCellInfo cellInfo in this.radGridView1.SelectedCells)
{
object zz = cellInfo.Item;
Customer cu = (Customer)zz;
textBox1.Text = cu.ContactTitle;
}
So if I could access the fields of Customer using the unique string i.e..
sting s = cu["City"]
then that would be a cleaner solution.
Any ideas ???
foreach (GridViewCellInfo cellInfo in this.radGridView1.SelectedCells)
{
GridViewColumn gvc = cellInfo.Column;
string uniqueName = gvc.UniqueName;
object zz = cellInfo.Item;
Customer cu = (Customer)zz;
if (uniqueName.Equals("City"))
{
textBox1.Text = cu.City;
}
else if (uniqueName.Equals("Address"))
{
textBox1.Text = cu.Address;
}
else
{
textBox1.Text = "To be written";
// And the rest of the column names.
}
}
I also wanted to change the cell background colour of the single cell(s)
But can only manage
cellInfo.Column.Background = new SolidColorBrush(Colors.Red);
Any idea how to get access to the actual cell. The item property only seems to be the data object e.g. Customer.
Help Help ......
Thanks Jim
Looking at the code-snippet you provided for running through the selected cells, I get the impression that you managed to resolve the issue. Am I right or am I missing something from your initial requirements ?
As for setting the background of the cells, may you share a bit more details about the exact purpose of setting it ? What are the view and functionality that you want to accomplish ? Generally, you might find interesting the implementation of CellStyleSelector.
Maya
the Telerik team
Typically users select cells and click the button. We want the cells to be highlighted.
The user selects more cells and clicks the button.
Then the additional cells are highlighted in addition to the first ones.
The "CellStyleSelector." seems to be dependant on the data.
It seems that you can get the column from cellInfo but not the actual cell.
Thanks
Jim
Getting the corresponding GridViewCell from the GridViewCellInfo is not quite easy since the virtualization of the grid is turned on by default. Consequently, only the visible cells can be accessed. Still, what you may do is to get the GridViewRow from the item you have already found and get its cells. It may be something similar to:
foreach (GridViewCellInfo cellInfo in this.clubsGrid.SelectedCells)
{
GridViewColumn column = cellInfo.Column;
string uniqueName = column.UniqueName;
object item = cellInfo.Item;
Club club = (Club)item;
var row = this.clubsGrid.ItemContainerGenerator.ContainerFromItem(cellInfo.Item) as GridViewRow;
foreach (GridViewCell cell in row.Cells)
{
if (cell.Column == cellInfo.Column)
{
cell.Background = new SolidColorBrush(Colors.Cyan);
}
}
}
I am sending you a sample project so that you can test the functionality.
Maya
the Telerik team