This is a migrated thread and some comments may be shown as answers.

[Solved] Selecting row

3 Answers 227 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Eduardo
Top achievements
Rank 1
Eduardo asked on 24 Mar 2009, 04:57 PM
How do I set a row for selected?
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

Sort by
0
Vlad
Telerik team
answered on 25 Mar 2009, 07:41 AM
Hi Eduardo,

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.
0
Eduardo
Top achievements
Rank 1
answered on 25 Mar 2009, 11:42 AM
I saw...
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"

0
Eduardo
Top achievements
Rank 1
answered on 25 Mar 2009, 02:00 PM
I solved this way:

 

// -> 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;

 

}

Tags
GridView
Asked by
Eduardo
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Eduardo
Top achievements
Rank 1
Share this question
or