Datagrid Problem

rHasan

Active member
Joined
Jan 10, 2007
Messages
43
Programming Experience
3-5
I have a form which displays a list of Colors from an access database table in a dataGrid, which has two field - colorID and ColorName. I've two text box in the form too. I want that when I click in a crow in the grid, that data will be displayed in the text boxes. I can then edit the data clicking the edit button if I like.

Please tell me how to do that!
 
Bind your textboxes to the same datasource.

As you are using VS 2005 this is really easy.

On your form, drop a grid and 2 textboxes on there.

Now, in the right pane, browse your datasources. Drop your color table onto your grid, then expand the table and drop the colorID field onto textbox1 and colorName onto textbox2.

Run your app and you will see that the textboxes change accordingly with the selected row.

You will then need to add some update code to your TableAdapter in order to save the changes you make back into Access.

HTH
 
As you've said you've already bound the grid, you should know how to bind the textboxes.

me.textbox1.databindings.add("text", dataset.table, "column")

As long as your textboxes are bound to the same bindingSource as the grid then the texboxes will change when the row changes.
 
seems like dataset.table is not recognized! there is an spelling like error showing. Will u pls explain the three parameters?

I really don't know how to bind text boxes! I searched a lot and couldn't find anywhere..thnx!
 
dataset = the name of your dataset

table = the name of the table you are binding to

column = the table column you are binding to

I.E. (me.dataset1.Customer, "CustomerName")


There are 100s of posts on this site explaining how to bind.
It even tells you in Online Help in VS2005.

Structure your search words correctly and you'll get the right results back.
 
Thnx a lot buddy! I got it all right!! Here is my code:

txtBuyerName.DataBindings.Add("text", objDataTable, "BuyerName")

Its working nicely! My textboxes are now correctly displaying the data when I am clicking on the grid cells! Thnx a l...o...t for ur quick reply!

HAPPY VALENTINE!
 
Glad you got it working. :D

A little advice, show some incentive and try to work out things for yourself. Asking people to write the code for you is bad practice for many reasons, and others will simply just not reply.

The major thing is you won't learn by copying straight from someone and you'll regret it in the future.

Search the forums for updating and adding to datagrids, there are plenty of posts out there that will point you in the right direction.

Good luck :)
 
Back
Top