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

Gridview, datatable, selected row

4 Answers 290 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marius
Top achievements
Rank 1
Marius asked on 17 Dec 2012, 09:07 AM
Hello!
I am using a gridview like this:

   
private void LoadGrid()
{
    DataTable dataTable = new DataTable();
    DataColumn itemIdColumn = new DataColumn("ItemId", typeof(int));
    DataColumn itemCodeColumn = new DataColumn("ItemCode", typeof(string));
    DataColumn itemNameColumn = new DataColumn("ItemName", typeof(string));
    DataColumn sellPriceColumn = new DataColumn("SellPrice", typeof(decimal));
    DataColumn vatValueColumn = new DataColumn("VatValue", typeof(decimal));
    DataColumn itemTypeColumn = new DataColumn("ItemType", typeof(int));
 
    dataTable.Columns.Add(itemCodeColumn);
    dataTable.Columns.Add(itemNameColumn);
    dataTable.Columns.Add(sellPriceColumn);
    dataTable.Columns.Add(vatValueColumn);           
    dataTable.Columns.Add(itemTypeColumn);
    dataTable.Columns.Add(itemIdColumn);
 
 
    dataTable.BeginLoadData();
    var lst = _relatedItemBc.GetItemsForMainGrid(FilteredItem);
    for (int i = 0; i < lst.Count; i++)
    {
        DataRow row = dataTable.NewRow();
        row["ItemCode"] = lst[i].ItemCode;
        row["ItemName"] = lst[i].ItemName;
        row["SellPrice"] = lst[i].SellPrice;
        row["VatValue"] = lst[i].VATValue;
        row["ItemType"] = lst[i].ItemType;
        row["ItemId"] = lst[i].ItemID;
        dataTable.Rows.Add(row);
    }
    dataTable.EndLoadData();
 
    rbcDataGridViewMain.MasterTemplate.BeginUpdate();
    rbcDataGridViewMain.DataSource = dataTable;
    rbcDataGridViewMain.MasterTemplate.EndUpdate();
}

How can i get the informations for the current row, the row i have selected?

Thank you!

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Dec 2012, 08:03 AM
Hi,

Try the following code.
C#:
private void button1_Click(object sender, EventArgs e)
        {
            string value = radGridView2.CurrentRow.Cells[0].Value.ToString();
        }

Thanks,
princy.
0
Marius
Top achievements
Rank 1
answered on 18 Dec 2012, 03:05 PM
Thank you very much!
Can you tell me if this is the fastest way to load data into radGridview?
0
Princy
Top achievements
Rank 2
answered on 19 Dec 2012, 05:09 AM
Hi Marius,

You can assign the DataSource property of RadGridView to to load data into RadGridView.

C#:
ArrayList arrayList = new System.Collections.ArrayList();
arrayList.Add(new MyObject(1, "Object one") );
arrayList.Add(new MyObject(2, "Object two") );
arrayList.Add(new MyObject(3, "Object three") );
radGridView1.DataSource = arrayList;

Please take a look into the following documentations for more information.
Binding to Array and ArrayList
Binding to DataTable or DataSet

Hope this helps.

Regards,
Princy.
0
Anton
Telerik team
answered on 19 Dec 2012, 03:12 PM
Hi Marius,

Thank you for writing.

The answer to this question - is depends. In your scenario when you bind the grid to a DataTable the data loading speed should be satisfying. 

One more thing to add is that you do not need to call Begin/EndUpdate when you are assigning a DataSource to the grid. These are needed when you manually add rows to the grid in order to suspend its updates.

Should you have any other questions, I will be glad to assist you.

Kind regards,
Anton
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
GridView
Asked by
Marius
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Marius
Top achievements
Rank 1
Anton
Telerik team
Share this question
or