Click here to Skip to main content
15,881,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.

Im reading a list of learners from an sql database through 3-tier architecture.

I need to add each learner individually with reference number (learnerID) to a datagridview. If there's more learners, then it should just add to current list.

I retrieve all learners from the businessLayer and place it in a List. Then i convert the List to an array.

C#
this.dgvLearners.DataSource = Blayer.GetLearners((int)learnerIDgo); 
    //get first learner
foreach (int id in learnerIDS)//reading from array of Lists
{
    learnerIDgo = id;
    this.dgvLearners.Rows.Add(Blayer.GetLearners((int)learnerIDgo));
    //get and add all the additional learners
}


Error - Doesn't allow me to add rows programmatically to a datagridview.
Posted
Comments
Firo Atrum Ventus 5-Oct-11 23:45pm    
Show us the code where you assign the value of learnerIDS and learnerIDgo
Xeshan Ahmed 6-Oct-11 1:41am    
send complete code

add rows work only if the grid is not data bond
 
Share this answer
 
Once you have assigned the datasource object on the datagrid view, it bound there.
You could bind it later.
Declaring another object of the same type as your Blayer.GetLearners((int)learnerIDgo) object should create a "list" type object.

You can then add to that new object (assuming it has an insert/add method on it)
Once you've added your extra's, bind it to the datagridview.

Hope this helps...
 
Share this answer
 
Comments
DJAppleboy 11-Oct-11 18:28pm    
Are you saying that i should add learners to a collection of list and then bind the list to the datagridview?
donaldrichardson 4-Nov-11 10:45am    
Sorry so late, but yes add learners to a collection list and then bind. So what you do is add the new info to your BLayer.GetLearners returned object and bind it after the fact.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900