WinFormsUser13232

Hello all, 
Well after searching MSDN and this forum, i've finally come to a brick wall. Here is what i'm trying to do: 

I am using the following code on my DataGrid

'======================================
' Set the MappingName for the first column...
        objTextCol.MappingName = "id"
        ' Set the new HeaderText...
        objTextCol.HeaderText = "ID"
        ' Add the column to the DataGridTableStyle...
        objDataGridTableStyle.GridColumnStyles.Add(objTextCol)
=============================================
All i want to do is retrieve the id value when the user clicks on the DataGrid row. Then, i can retrieve the detail for that record elsewhere in my code. 

Help.
Thanks in advance.

Richard M.


Re: Windows Forms Data Controls and Databinding It can't be this hard!!??

WinFormsUser

Databinding might be the simplest method:
dgPrepare.SetDataBinding(dsPrepare, "PrepareOrders");
lblProduct.DataBindings.Add("Text", dsPrepare, "PrepareOrders.Product_Info");

OR

dgPrepare.SetDataBinding(dsPrepare.PrepareOrders);
lblProduct.DataBindings.Add("Text", dsPrepare.PrepareOrders, "Product_Info");

dgPrepare: DataGrid
dsPrepare: DataSet
PreepareOrderes: DataTable
Product_Info: A column in the DataTable

If you set this DataBinding in the constructor.  Then as soon as the user changes his selection, the value in the label will change too.

Just make sure you clear the Binding in Dispose
dgPrepare.DataBindings.Clear();
lblProduct.DataBindings.Clear();

Also if you are trying to do a Master-Detail Datagrid, where you have two datagrids, one with Master Table and the other with related records to each row then you might want to look into DataRelations and Typed Dataset.  These will make codding a lot easier.

Here a sample of how I show related records into a different grid:
dgDist.SetDataBinding(dsPrepare, "PrepareOrders.PrepareOrdersToOrders");

Hopefully the code gives you enough to work with.





Re: Windows Forms Data Controls and Databinding It can't be this hard!!??

WinFormsUser

http://www.windowsforms.net/Forums/ShowPost.aspx tabIndex=1&tabId=41&PostID=16425

This could be useful for you....




Re: Windows Forms Data Controls and Databinding It can't be this hard!!??

GregN

Gosh it is REALLY hard until one finds this thread. - 3 days to get here alone...

I tried disposing the datagrid and the dataset table and still no joy.

My problem was just that. The datagrid was still bound to the dataset.

Creating a new dataset table didn't help as it wouldn't load into the datagrid.

After judicious rebuilding of original code

with a simple dataset.Clear() command which empties all tables in the dataset I was able to display the new data.

Signed C# coder(with less hair)