Passing values from a DataRepeater control in VB.net

Hello everyone.

I have a dataRepeater on a form that displays some data from an underlying DataTable 'dsMovies'. The data repeater contains a textbox that is bound to a field in the data table  (see code below)

        tbMovieNames.DataBindings.Add(New Binding("Text", dsMovies, "title"))

        DataRepeater1.DataSource = dsMovies
        DataRepeater1.AllowUserToAddItems = False
        DataRepeater1.AllowUserToDeleteItems = False

The dataRepeater displays the data (which is a list of movies) as intended. What I want to do now, is to collect some values from a row when the user clicks on the textbox in the datarepeater. E.g. If a user clicks on a textbox (that displays the movie title), I want to save the movieID of that selected title in a global variable and then open another form that will display more information about the selected movie.

I dont have any problems opening a new form when the textbox is clicked on but I dont know how to save the movieid of the selected record. The underlying data table retrieves movieid, title and year from the database.

Could someone give me a step by step guide on how to do this?

Many thanks

Rob
LVL 11
shorakAsked:
Who is Participating?
 
shorakConnect With a Mentor Author Commented:
Hi.. Thanks for your help but I have found part of the solution from this post.

http://social.msdn.microsoft.com/Forums/en-US/vbpowerpacks/thread/c9c229d0-dcf9-47c5-89c7-03cc56152018

All I needed was this part of the code in my textbox click event:

GlobalValue =   DataRepeater1.CurrentItem.Controls("TextBox").Text

This will pass the contents of the texbox to the global variable. Now.. what I need to do is pass the value of a field in the underlying datatable to the global variable as I dont want to display the field in the datarepeater. One way to do it would be to create a textbox for that field but make it invisible. Do you know of an alternative way to do it?

Thanks again

Rob


0
 
daveamourCommented:
Is this a Repeater or a Gridview?
This is a Winforms app right?
0
 
shorakAuthor Commented:
Its a dataRepeater control (part of Vb Powerpack 3) and yes.. it is a winforms app. I am guessing that it behaves similarly to a datagridview control but allows you to create a custom layout of the fields as well as adding controls to each row.

Rob
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
daveamourCommented:
Ok well certainly in a GridView you can have an event handler for code such as CellClick eg:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
    MessageBox.Show(e.RowIndex.ToString());
}
Are there not simillar events in the Repeater Control?
0
 
shorakAuthor Commented:
I'm quite new to vb.net so I'm not sure if if a datarepeater control has an even handler. I have found this link that might help but I think the code is in C# and not vb.net.
http://www.vbforums.com/showthread.php?t=557147

any ideas?

Rob
0
 
daveamourConnect With a Mentor Commented:
If you click on the control in design view and then on the properties window in the bottom right of visual studio there will be a bolt of lightenting.  Click this and it will show you all of the events for that control.
If you find an event you want to use - ie fire some code when that event happens then next to the event will be a blank area - double click on that.
Visual Studio will then write the event handler for you which will be simillar to this:

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
    MessageBox.Show(e.RowIndex.ToString());
}
The e is used to pass information about the event such as which rows was clicked.
0
All Courses

From novice to tech pro — start learning today.