DataGridView - when using Fill / Append Methods don´t allow AllowUserToAddRows

0
0

Hi.

I have a grid that loads data from a List trough Fill or Append methods.

This grid don´t needs to be bound, as receives the data from an API.

I´m working on the premisse that the the fill/append methods is only a fast way to load data, then disconnect from the source.

1 – When using this code, the AllowUserToAddRows functionality DON’T work after the data load.

————————————————————————————————-

var lista = await vwGroups.GetGroups(account, status);

var bs = new BindingSource(lista, null);

dg1.Columns[1].DataPropertyName = “name”;
dg1.Columns[2].DataPropertyName = “description”;
dg1.Columns[3].DataPropertyName = “status”;
dg1.Columns[4].DataPropertyName = “groupGUID”;

dg1.Fill(lista);


2 – When load data using foreach works, as expected.

List<Groups> g = new List<Groups>();

var listGroups = await vwGroups.GetGroups(conta, status);

//var bs = new BindingSource(lista, null);

//dg1.Columns[1].DataPropertyName = “name”;
//dg1.Columns[2].DataPropertyName = “description”;
//dg1.Columns[3].DataPropertyName = “status”;
//dg1.Columns[4].DataPropertyName = “groupGUID”;

//dg1.Fill(lista);
dg1.AllowUserToAddRows = true;

foreach (Groups item in listGroups)
{
int newline = dg1.Rows.Add();

dg1.Rows[newline].Cells[1].Value = item.Name;
dg1.Rows[newline].Cells[2].Value = item.Description;
dg1.Rows[newline].Cells[3].Value = item.Status;
dg1.Rows[newline].Cells[4].Value = item.GroupGUID;

}

Application.Update(this);

Is it correct ? Or I miss something ?

Regards,

 

  • You must to post comments
0
0

Hi Marcelo,

this issue was logged as #2649 and is now fixed in Wisej release 2.2.48

Best regards
Frank

  • You must to post comments
0
0

It’s a bug. The workaround is easy: just set AllowUserToAddRows after filling and it works fine.

this.dataGridView1.Fill(bs);
this.dataGridView1.AllowUserToAddRows = true;

  • You must to post comments
0
0

Hi Frank.

Got it.

The problem occurs when you set the property AllowUserToAddRows in design mode, before the Fill method, even if you have the method in code.

Try it …

Regards

 

  • You must to post comments
0
0

Marcelo,

your first code snippet misses the setting of AllowUserToAddRows. Is that correct?
I have tried to reproduce in attached sample but it works fine.
Can you please give it a try?

Best regards
Frank

  • Marcelo Blank
    No. The first snippet has too the code to set AllowUserToAddRows … I´ll verify your demo peoject …
  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.