0

I have an application with multiple datagridviews in a tabcontrol. One of the tabcontrols has 4 columns that are filled by the datasource. I don't use autogenerate columns, but use the DataPropertyName to bind values to the columns.

I also have 2 columns i create, wich are filled manually, after assigning the DataSource.

Values in this datagridview are filtered values from a datagridview somewhere else in the application.

When i filter, then go to the tab containing the datagridview, the manual columns are empty. Changing the filter (but not the results) fills those colums.

How can i get the columns that are manually filled to always show their values?

Calling Refresh() or Update() on the datagridview doesn't solve my problem

Short version of my code: I actually use a class that inherits from DataGridView

//fill datagridview
PcbLink[] links = Service.Instance.Client.queryPcbLinks();

List<Pcb> pcbs = new List<Pcb>();

foreach (PcbLink link in links)
{
  PcbFilter pcbfilter = new PcbFilter();
  pcbfilter.pcb_id = link.pcb_id;
  Pcb[] res = Service.Instance.Client.queryPcbs(pcbfilter);
  pcbs.Add(res[0]);//only first element because pcb_id should always be unique -> only one row
}
cdgvUsage.SetData(pcbs);//setData is used as cdgvUsage.DataSource = pcbs, but does some stuff internally
for (int i = 0; i < links.Length; i++)
{
  SortableBindingList<Pcb> dataSource = cdgvUsage.GetData<Pcb>();
  cdgvUsage["count", i].Value = links[i].count;
  char variantchar = (char)('a' + (char)(dataSource[0].variant));
  cdgvUsage.Columns["variant"].ValueType = typeof(string);
  cdgvUsage["variant", i].Value = variantchar.ToString();
}
King King
  • 61,710
  • 16
  • 105
  • 130
RazorEater
  • 265
  • 2
  • 14

1 Answers1

0

I believe after asigning DataSource to the dataGridView changes must be saved in datasource also otherwise they will not be reflected in the dataGridView (as it takes data from datasource everytime you do Refresh() or Update()).

Make sure manually filled values are stored in dataSource.

IFlyHigh
  • 546
  • 2
  • 9
  • 20
  • The columns i enter manually aren't bound to the DataSource. They are only bound to the datagridview itself – RazorEater Nov 21 '13 at 14:54
  • ok got your point. Did you try CommitEdit() ? If not check for first IsCurrentCellDirty[^] and IsCurrentRowDirty[^], if both return true then try using CommitEdit. Still if it does not work then please provide related snippet of your code. – IFlyHigh Nov 21 '13 at 15:00
  • this does not seem to work aswell. The values are actually assigned to the cells (and the current cell and row aren't dirty, the assignment finished). The values seem to be there, but not showing – RazorEater Nov 21 '13 at 15:14
  • hmm.. with you code I cant find any problem. May be you can try an alternative. Create a new class with all the fields you need in you datagridview. Make an object of this class and fill it with the manually entered values and values from datasource and bind this object to datagridview. Just an alternative! – IFlyHigh Nov 21 '13 at 15:18