Comments (5)
Hello,
That must be something related to your datatable, so to your elemento.Value
If you try building it with a sample datatable it works. I see you cast the Value to a DataTable, is it a DataTable?
Find below a test code that I've tested.
public void createDGV(AdvancedDataGridView dgv)
{
// sample datatable
DataTable dataTable = new DataTable("test");
dataTable.Columns.Add("col1", typeof(int));
dataTable.Columns.Add("col2", typeof(string));
dgv.Dock = DockStyle.Fill;
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = dataTable;
dgv.DataSource = bindingSource;
dgv.RowHeadersVisible = false;
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
dgv.AllowUserToAddRows = false;
}
I've try to replicate your
from advanceddatagridview.
Hello David, thanks so much for your answer!
I work closely with Layla and continued digging into the issue as per your guidance.
I confirm to you that the Value is indeed exactly a DataTable.
So what I did was instead of inserting my DataTable, I created a new one at the same time and I kept having the same problem,
public void createDGV(KeyValuePair<string, object> elemento, AdvancedDataGridView dgv)
{
dgv.Dock = DockStyle.Fill;
DataTable dt = new DataTable();
DataTable dataTable = new DataTable("test");
dataTable.Columns.Add("col1", typeof(int));
dataTable.Columns.Add("col2", typeof(string));
dt = dataTable;
BindingSource bindingSource = new BindingSource();
try
{
bindingSource.DataSource = dt;
dgv.DataSource = bindingSource; // Here's the error
}
catch { }
dgv.RowHeadersVisible = false;
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
dgv.AllowUserToAddRows = false;
dgv.SortStringChanged += (sender, e) => dgv_Dados_SortStringChanged(sender, e, bindingSource);
dgv.FilterStringChanged += (sender, e) => dgv_Dados_FilterStringChanged(sender, e, bindingSource);
}
I'm suspecting that the problem is in inserting several ADGV in different TabPages in the same TabControl.
As shown in the code below, for each report, I create a new ADGV and a new TabPage, and insert it into the existing TabControl.
The error in the code only appears when inserting the second report.
foreach(var elemento in resultsList)
{
var tab = new TabPage();
tab.Name = "tab_" + elemento.Key;
tab.Text = elemento.Key;
tab_Results.Controls.Add(tab);
tab.Padding = new Padding(4, 4, 4, 4);
tab.BackColor = Color.White;
AdvancedDataGridView dgv = new AdvancedDataGridView();
dgv.ReadOnly = true;
tab.Controls.Add(dgv);
createDGV(elemento, dgv);
}
It would be really appreciated if you could help us one more time.
Kind regards
from advanceddatagridview.
Hello @rhandalfm
I'm using several ADGV with no problem. Can you build a sample project?
from advanceddatagridview.
Helli @davidegironi !
Thanks again for your help and for responding quickly.
I managed to reproduce the problem in this code below.
https://github.com/rhandalfm/ADGVTest
Reinforcing that the error only happens when inserting the second tab.
With this part of the code inside the try catch, the code continues to throw the error but manages to run to the end (most of the time) and insert the ADGVs in the tabs.
try
{
bindingSource.DataSource = dados;
dgv.DataSource = bindingSource; // Here's the error
}
catch
{
;
}
Kind regards.
from advanceddatagridview.
Hello,
At first you have to create it on FormLoad event, then you have to follow the following order:
- create the dgv
- add to control
- select the tab (this will give all the underline event a dgv a shot)
- custom set the dgv columns
Find your form1.cs code modified below:
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Zuby.ADGV;
namespace ADGVsample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
test();
}
private void test()
{
for (int i = 0; i < 3; i++)
{
var tab = new TabPage();
tab.Name = "tab_" + i.ToString();
tab.Text = i.ToString();
tab_Resultado.Controls.Add(tab);
tab.Padding = new Padding(4, 4, 4, 4);
tab.BackColor = Color.White;
AdvancedDataGridView dgv = new AdvancedDataGridView();
dgv.ReadOnly = true;
createDGV(dgv);
tab.Controls.Add(dgv);
tab_Resultado.SelectedTab = tab;
setDGVcolumns(dgv);
}
}
public void createDGV(AdvancedDataGridView dgv)
{
dgv.Dock = DockStyle.Fill;
DataTable dados = new DataTable();
dados.Columns.Add("col1", typeof(int));
dados.Columns.Add("col2", typeof(string));
BindingSource bindingSource = new BindingSource();
try
{
bindingSource.DataSource = dados;
dgv.DataSource = bindingSource;
}
catch
{
;
}
dgv.RowHeadersVisible = false;
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells;
dgv.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
dgv.AllowUserToAddRows = false;
dgv.SortStringChanged += (sender, e) => dgv_Dados_SortStringChanged(sender, e, bindingSource);
dgv.FilterStringChanged += (sender, e) => dgv_Dados_FilterStringChanged(sender, e, bindingSource);
}
public void setDGVcolumns(AdvancedDataGridView dgv)
{
DataTable dados = (DataTable)((dgv.DataSource as BindingSource).DataSource);
foreach (DataColumn coluna in dados.Columns)
{
if (coluna.DataType == typeof(long) || coluna.DataType == typeof(int))
{
dgv.Columns[coluna.ColumnName].DefaultCellStyle.Format = "N0";
dgv.Columns[coluna.ColumnName].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
}
else
if (coluna.DataType == typeof(double))
{
dgv.Columns[coluna.ColumnName].DefaultCellStyle.Format = "N2";
dgv.Columns[coluna.ColumnName].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
}
}
}
private void dgv_Dados_SortStringChanged(object sender, EventArgs e, BindingSource bindingSource)
{
bindingSource.Sort = ((AdvancedDataGridView)sender).SortString;
}
private void dgv_Dados_FilterStringChanged(object sender, EventArgs e, BindingSource bindingSource)
{
bindingSource.Filter = ((AdvancedDataGridView)sender).FilterString;
}
}
}
from advanceddatagridview.
Related Issues (20)
- .NetCore WinForm App Crashes
- Filter records based over the whole records when I use select top x HOT 3
- Workaround or fix for column names containing square brackets HOT 1
- Filtering only shows selected values in the filter dialog HOT 4
- Set filter programmatically HOT 7
- how to disable checkbox cell after filter data? HOT 2
- Setting FilterAndSortEnabled = false does not prevent changed cells being removed from collection HOT 7
- how to speed up filter menu in adgv? HOT 1
- AdvancedDatagridView - 1.2.28405.11 - Problem when clicking on filter / search drop down HOT 2
- Filter/Sort doesn't work on DataGridViewComboBoxColumn HOT 2
- How to use Advanced DataGridView Search Tool Bar HOT 1
- High DPI screens have tiny icon for filtering HOT 11
- filter button_click events HOT 4
- Verticle Scroll Bars Disappear HOT 2
- Filter Support On Toolbar HOT 4
- create progressbar in advancedatagridview
- Filtering columns with fonts like wingdings HOT 11
- how to paginating data in advanced data grid view? HOT 1
- Column Header Size Issue with ADGV created in previous version. HOT 16
- Query - Is this possible? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from advanceddatagridview.