Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello again. My question this week is about data binding. For example, I am attempting to write a simple program taht will have a form with a list box and a data grid as controls. Just for fun I will make it a list of my DVD's that can be searched by genre.

So if the user selects comedy in the list box, a list of all of the comedy dvds will apear in the datagrid. My problem though is that I am setting the datagrid's data source and data member properties at design time. What I did was generate a dataset for each genre of movie (Kids, action, drama, etc) but I can only bind one data set to the flex grid at a time, so when the user chooses the first option the movies appear in the data grid perfectly but when you chose the next option nothing shows up. Can I set these properties so that the databinding takes place after the user makes his choice? I guess this would be considered at run time right?

Posted

Im sorry could you give me an example of the proper syntax for that? Im sorry,if this is a lame question, Im new and Im learning this stuff on my own with only a few books and this forum. thank you for your time and your help.

BTW your picture kind of scares me.

Posted

Well, I'm more or less the blind leading the blind here as I've never actually written anything in ADO.NET yet, but if I'm not mistaken the proper syntax would be..

 

(Using C#)

dataGrid1.DataSource = yourDataSet.Tables["YourTable"].DefaultValue;

 

(Using VB)

dataGrid1.DataSource = yourDataSet.Tables("YourTable").DefaultValue

Gamer extraordinaire. Programmer wannabe.
Posted
I still cant get it to work. It seems like I should bind the dataset to the datagrid after the user makes his selection in the listbox. I need to bind the data that corresponds with the selection in the listbox. does this make sense?
  • *Experts*
Posted

Use the following search in your .NET help (minus the double quotes):

"walkthrough creating master detail windows"

 

It should find a how-to titled "Walkthrough: Creating a Master-Detail Windows Form" which shows how to bind a ListBox and as you click entries, it automatically fills a filtered DataGrid.

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

No problem :)

 

If you want to learn how to bind a grid to a DataView (a filtered, sorted view of a DataTable) let me know. Ah heck, here it is...

 

Assume you have two tables, Table1 and Table2, which both contain a key column named State. You want to show a list of cities from Table2 that match the state currently chosen from Table1 (which is bound to a listbox).

string state = listBox1.Text;

DataView dv = new DataView(ds.Tables["Table2"], "state = '" + state.Replace("'", "''") + "'", "Cityname", DataViewRowState.CurrentRows);

dataGrid1.DataSource = dv;

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...