PC Review


Reply
Thread Tools Rate Thread

DataGridView and Two Array Sources

 
 
Trecius
Guest
Posts: n/a
 
      7th May 2009
Hello, Newsgroupians:

I have a ListBox that has a .DataSource of an array of Person[]. I am also
using a CurrencyManager to move the position when the Selected_Index of the
ListBox also changes. This works for text boxes and other controls as
follows...

this.TextBox1.DataBindings.Add("Text", lstPeople, "Name");

As you can see, the person's name will populate the textbox.

However, I have a DataGridView that I would like to populate as well. The
first two columns of the DataGridView come from a static dictionary: the key
is the identifier of the task, and the value is the task name. I also want
to add a third column to the DataGridView that comes from the Person
datatype. It will be a boolean value, indicating if the person has
successfully completed the task (True or False).

How can I make it so I that when the Person is changed in the Listbox, the
DataGridView will also change the third, or last, column?

On a short note, I can populate the first two rows, using my dictionary, as
follows:

BindingSource bind = new BindingSource();
bind.DataSource = dictTasks;
GridView1.DataSource = bind;

However, how should I get my last column in there that corresponds to the
Person completing the job or not? Thank you.


Trecius
 
Reply With Quote
 
 
 
 
Trecius
Guest
Posts: n/a
 
      7th May 2009
Well, it's not quite what I'm looking for.

When the actual user of the program selects a person that is found in the
ListBox, all the contents on the form change; for example, the First Name
TextBox, the LastName TextbBox. Etc.

It changes by the following event...

private void ListBoxPerson_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.ListBoxPerson.SelectedIndex >= 0)
{
this.cm.Position = this.ListBoxPerson.SelectedIndex;
}
}

NOTE: this.cm is the CurrencyManager.

This allows the controls on the page to dynamically change. However, the
Person also has an Array of tasks that were completed. I'm trying to
dynamically change the DataGridView too with respect to the change of index
of the ListBoxPerson.]


Trecius

"Peter Duniho" wrote:

> On Thu, 07 May 2009 11:46:17 -0700, Trecius
> <(E-Mail Removed)> wrote:
>
> > [...]
> > How can I make it so I that when the Person is changed in the Listbox,
> > the
> > DataGridView will also change the third, or last, column?

>
> Do you mean when the specific Person object changes, or when the "person"
> selected in your ListBox changes (i.e. the ListBox selection changes)?
> Why is the CurrencyManager relevant at all?
>
> > On a short note, I can populate the first two rows, using my dictionary,
> > as
> > follows:
> >
> > BindingSource bind = new BindingSource();
> > bind.DataSource = dictTasks;
> > GridView1.DataSource = bind;
> >
> > However, how should I get my last column in there that corresponds to the
> > Person completing the job or not? Thank you.

>
> Hard to say what the best approach is. I suppose you could create a
> wrapper class that implements, for example, IBindingList, and then
> provides a unified view onto the dictionary and associated data via a
> specific element type. But whether that's most appropriate in your
> situation, no one can say because you didn't bother to post a
> concise-but-complete code example that reliably demonstrates what's going
> on.
>
> The short answer is: you'll need some kind of "change" event somewhere to
> update things automatically based on changes elsewhere in your data. If
> you simply need an update based on a ListBox selection change, that's
> easy, as ListBox already exposes such "change" events. If you need an
> update based on when a specific Person object changes, then either your
> Person object itself needs to have a "change" event, or you need some
> mediator that knows when the Person object changes and can be used to
> raise an event or otherwise update the UI.
>
> Of course, all of that is probably pretty obvious. But that's about as
> much advice as anyone can give in response to such a vague question.
>
> Pete
>

 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      8th May 2009
Trecius,

I am always curious if people are doing simple things difficult or that
there is a reason.

Why are you using the dictionary at all, is not simpler to create a class
Person and use that as the items from a generic list?

Cor

"Trecius" <(E-Mail Removed)> wrote in message
news:33C724D7-E2FD-4345-9746-(E-Mail Removed)...
> Hello, Newsgroupians:
>
> I have a ListBox that has a .DataSource of an array of Person[]. I am
> also
> using a CurrencyManager to move the position when the Selected_Index of
> the
> ListBox also changes. This works for text boxes and other controls as
> follows...
>
> this.TextBox1.DataBindings.Add("Text", lstPeople, "Name");
>
> As you can see, the person's name will populate the textbox.
>
> However, I have a DataGridView that I would like to populate as well. The
> first two columns of the DataGridView come from a static dictionary: the
> key
> is the identifier of the task, and the value is the task name. I also
> want
> to add a third column to the DataGridView that comes from the Person
> datatype. It will be a boolean value, indicating if the person has
> successfully completed the task (True or False).
>
> How can I make it so I that when the Person is changed in the Listbox, the
> DataGridView will also change the third, or last, column?
>
> On a short note, I can populate the first two rows, using my dictionary,
> as
> follows:
>
> BindingSource bind = new BindingSource();
> bind.DataSource = dictTasks;
> GridView1.DataSource = bind;
>
> However, how should I get my last column in there that corresponds to the
> Person completing the job or not? Thank you.
>
>
> Trecius


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
datagridview from two data sources mcnews Microsoft VB .NET 0 7th Sep 2011 07:38 PM
DataGridView and array properties kh Microsoft Dot NET Framework Forms 0 7th Dec 2007 06:33 PM
Cannot add row to DataGridView based on array Andrus Microsoft C# .NET 2 21st Aug 2007 02:45 PM
Array to DataGridView Steve Microsoft C# .NET 1 15th Oct 2006 09:36 PM
DataGridView and Array Marek Microsoft C# .NET 0 18th Jul 2006 12:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:44 AM.