exemples:
grid.Row[0].selected = true;
grid.Row[0].Select() = true;
grid.SelectedItem = item;
I'm also having difficult on get the row (index, value, record, item)
3 Answers, 1 is accepted
I've attached small demo to illustrate you how to achieve your goal.
Greetings,
Vlad
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
below my code:
public partial class Country : UserControl
{
object record;
// -> Constructor
public Country()
{
InitializeComponent();
LoadGrid();
}
// -> Asynchronous method for load grid
private void LoadGrid()
{
ServiceFactory session = new ServiceFactory();
session.ExecuteServiceMethod<ConsulteService.LoadDataGridCompletedEventArgs>(typeof(ConsultServiceClient).FullName, LoadDataGridCompleted, "LoadDataGrid", "Country", "");
}
// -> Load Result Service
void LoadDataGridCompleted(object sender, LoadDataGridCompletedEventArgs e)
{
grid.DataBind(e.Result); // -> Extension Method
// -> *** IT ISN'T WORK!!!
if (record != null)
grid.SelectedRecord = grid.Records[grid.Records.IndexOf(record)];
}
public static void DataBind(this RadGridView grid, byte[] data)
{
MemoryStream str = new MemoryStream(data);
DataSet ds = new DataSet("DS");
ds.ReadXml(str);
ds.AcceptChanges();
grid.AutoGenerateColumns = false;
grid.ItemsSource = ds.Tables[0].DefaultView;
}
void btnUpdateRecord_Click(object sender, RoutedEventArgs e)
{
record = grid.SelectedRecord;
// code of record update;
LoadGrid();
}
}
then, when I use the IndexOf() method, It return me "-1"
// -> Grid
public static void DataBind(this RadGridView grid, byte[] data)
{
int index = 0;
MemoryStream str = new MemoryStream(data);
DataSet ds = new DataSet("DS");
ds.ReadXml(str);
ds.AcceptChanges();
grid.AutoGenerateColumns =
false;
// -> Prepara o posicionamento da linha da grid.
if (grid.SelectedItem != null)
{
object handle = grid.SelectedItem.GetValue("handle");
if (handle != null && (int)handle != 0)
{
DataRow[] rows = ds.Tables[0].Select(string.Format("handle = {0}", handle));
if(rows != null && rows.Length > 0)
index = ds.Tables[0].Rows.IndexOf(rows[0]);
}
}
// -> popula a grid.
grid.ItemsSource = ds.Tables[0].DefaultView;
if (index == -1)
index = 0;
if (index == 0 && grid.Records.Count > 0)
index = grid.Records.Count - 1;
// -> Seleciona uma linha.
grid.Records[index].IsSelected =
true;
}
