Select datagrid item to display details

  • Thread starter Thread starter Dave C
  • Start date Start date
D

Dave C

I have a datagrid and want to be able to have the user select an item
and then display details regarding that item in additional text boxes
(instead of user having to scroll over in a wide data grid). How
would I go about finding the row selected (or if user selected a
particular cell in a row) and placing the additional data elements in
text boxes?
 
watch this code:

int Line = dtgInvent.CurrentCell.RowNumber;
if (Linea > -1)
{
txtArtic.Text = TInvent.Rows[Line].ItemArray.GetValue(0).ToString();
}


Where dtgInvent is the datagrid, and TInvent is the DataTable (set as
dtgInvent´s datasource)
Put it in the datagrid´s mouseup event.

Regards,
 
An alternative is to use the CurrentRowIndex and a DataRow. Something like:

If dsTempItems.Tables(0).Rows.Count > 0 Then
rowIndex = dgTempItems.CurrentRowIndex
If rowIndex >= 0 Then
itemRow = dsTempItems.Tables(0).Rows(rowIndex)
tbxItem.Text = itemRow("Item")
etc.

Where dsTempItems is a DataSet
dgTempItems is a DataGrid
itemRow is a DataRow


Ibai Peña said:
watch this code:

int Line = dtgInvent.CurrentCell.RowNumber;
if (Linea > -1)
{
txtArtic.Text = TInvent.Rows[Line].ItemArray.GetValue(0).ToString();
}


Where dtgInvent is the datagrid, and TInvent is the DataTable (set as
dtgInvent´s datasource)
Put it in the datagrid´s mouseup event.

Regards,
--
Ibai Peña

Dave C said:
I have a datagrid and want to be able to have the user select an item
and then display details regarding that item in additional text boxes
(instead of user having to scroll over in a wide data grid). How
would I go about finding the row selected (or if user selected a
particular cell in a row) and placing the additional data elements in
text boxes?
 
Thanks, but is there a Visual basic equivalent? Seems that setting to
exact row index does not work in vb.net for compact?


John Atkins said:
An alternative is to use the CurrentRowIndex and a DataRow. Something like:

If dsTempItems.Tables(0).Rows.Count > 0 Then
rowIndex = dgTempItems.CurrentRowIndex
If rowIndex >= 0 Then
itemRow = dsTempItems.Tables(0).Rows(rowIndex)
tbxItem.Text = itemRow("Item")
etc.

Where dsTempItems is a DataSet
dgTempItems is a DataGrid
itemRow is a DataRow


Ibai Peña said:
watch this code:

int Line = dtgInvent.CurrentCell.RowNumber;
if (Linea > -1)
{
txtArtic.Text = TInvent.Rows[Line].ItemArray.GetValue(0).ToString();
}


Where dtgInvent is the datagrid, and TInvent is the DataTable (set as
dtgInvent´s datasource)
Put it in the datagrid´s mouseup event.

Regards,
--
Ibai Peña

Dave C said:
I have a datagrid and want to be able to have the user select an item
and then display details regarding that item in additional text boxes
(instead of user having to scroll over in a wide data grid). How
would I go about finding the row selected (or if user selected a
particular cell in a row) and placing the additional data elements in
text boxes?
 
That is vb.net from a CF program!

rowIndex is an unnecessary temporary variable introduced for "clarity".
There could well be another rowindex variable but I omitted showing the
local declaration of my integer rowIndex.

John.


Dave C said:
Thanks, but is there a Visual basic equivalent? Seems that setting to
exact row index does not work in vb.net for compact?


"John Atkins" <[email protected]> wrote in message
An alternative is to use the CurrentRowIndex and a DataRow. Something like:

If dsTempItems.Tables(0).Rows.Count > 0 Then
rowIndex = dgTempItems.CurrentRowIndex
If rowIndex >= 0 Then
itemRow = dsTempItems.Tables(0).Rows(rowIndex)
tbxItem.Text = itemRow("Item")
etc.

Where dsTempItems is a DataSet
dgTempItems is a DataGrid
itemRow is a DataRow


Ibai Peña said:
watch this code:

int Line = dtgInvent.CurrentCell.RowNumber;
if (Linea > -1)
{
txtArtic.Text = TInvent.Rows[Line].ItemArray.GetValue(0).ToString();
}


Where dtgInvent is the datagrid, and TInvent is the DataTable (set as
dtgInvent´s datasource)
Put it in the datagrid´s mouseup event.

Regards,
--
Ibai Peña

"Dave C" <[email protected]> escribió en el mensaje
I have a datagrid and want to be able to have the user select an item
and then display details regarding that item in additional text boxes
(instead of user having to scroll over in a wide data grid). How
would I go about finding the row selected (or if user selected a
particular cell in a row) and placing the additional data elements in
text boxes?
 
Back
Top