Listview not showing first row per each page - c#

I have a list view with which I am displaying a dataset. There is also a datapager.
The problem is, per each page, the first row of the dataset is not displayed in the list view.
So, the datapager displays text "showing element 1-10 of 22" but on the page, only 9 elements are displayed. The code is too big and complicated to paste here.
My question is, generally :
what can be the problem when the DataSet is right but after the binding, the listview shows 1 row less on each page.
I know my question is not specific enough, but I have to solve this problem and I need general ideas on where to look or how to debug, or what generally causes this kind of "first row not shown" problem.
Thanx

It's more than likely you're either not showing the first row, or the last row in the set. Check your conditions and comparisons.
Note that a DataSet is 0 based - the first row is .Rows[0], not .Rows[1]

The problem is solved. I dont know exactly what the problem was. This is a project developed by a team of programmers, and the bug was caused by something irrelevant to the context that I explained. Thank you all for the discussion.

Related

How does one get rid of this design-time row in the DataGridView row at run-time?

I'm using a DataGridView in a WinForm for the very first time, and have run into an odd problem.
I'm trying to populate the DataGridView control from the database. I'm not binding it to a dataset or anything, but retrieving a set of rows from a Sqlite query. I am then populating the rows programmatically from the data retrieval result. The grid is set up like this (as it appears in the designer):
What happens at runtime is fine, except for what appears to be a "phantom" row, which shows up in the grid as it appears in the designer, as the last row (blank or unpopulated), when I finish loading the grid. I've tried clearing the rows:
DataGridView.Rows.Clear();
But this doesn't clear anything. Trying to remove or make this row invisible fails with an exception because it's apparently uncommitted.
How do I get rid of the thing?
After entering the question in its entirety, I tried one last time to see if there was something that stood out. So I examined the properties of the DataGridView in close detail and wondered about some of the properties whose function I wasn't sure about.
The answer turned out to be the property AllowUserToAddRows. The "uncommitted row", as the exception designated it, is the place where the user would add the information for a new row that is to be inserted! Since this implementation of the grid is intended to be for editing of existing rows only, setting this property to False removed the apparently "bogus" row, and solved my problem.
And incidentally removed the row from the designer.

Page header is not repeating in rdlc report when two tablix is having two dataset

I'm having a one strange scenario. Before going into it, I want to say that I'm very beginner to this rdlc report. Hence I'm struggling to resolve it.
What I want is ?
I want to show the page header in all the pages.
What I have is ?
I'm having one header part which is having few textboxes and the body part which is having two tablix. Here, the two tablix consists of two difference datasets. The first tablix is grouped under Group1.
What the issue I face is ?
The first tablix consists of 50 records, that occupies three pages. In all the three pages, the header part is visible. When the second tablix is coming into the fourth page, all the header part turned into # error. Really struggling a lot to solve this.
What I tried is ?
Opened Advanced Mode in the Groupings pane.
Clicked static and changed the Keepwithgroup = after and Requestonnewpage = true.
Note : I did this for the two tablix but nothing works. Also I'm not sure that this will give the way.
Also I checked in report xml file also.
Checked Repeat row on each page and Repeat column on each page.
Hope you understand my problem. Kindly guide me where I'm making mistake. Thanks in advance.

DataGridView error after applying BindingSource.Filter which resulting Zero rows?

I don't understand why this can happen. I have a DataGridView whose DataSource is set to a BindingSource (for filtering and navigating purpose).
myDataGridView.DataSource = myBindingSource;
I have a list of items, Clicking on 1 item will apply a corresponding filter for myBindingSource and in result show only rows which meet the criteria on myDataGridView. Like this:
private void ItemsClicked(object sender, ItemClickedEventArgs e){
myBindingSource.Filter = e.FilterExpression;
}
That works OK when I click on items which make myDataGridView show at least 1 row. But the thing becomes bad when I click on any item which result to 0 rows meeting the corresponding filter expression. The myDataGridView should be empty normally but it throws a lot of exceptions in some dialogs (appeared consequently) (the exceptions are not shown in the code editor window in yellow marker), here is a snapshot of the error dialog:
After clicking the OK button, it still shows me another (the same one) dialog, .... it continues showing many dialogs (which have the same message) until it stops all. I can't understand what that is. I don't know if you need more info but I hope you have experienced a similar kind of exception and give me some suggestion on how to fix this. The dialog says about DataError event, but I don't understand why there is any error here? Please notice that all the Filter will be OK if there at least 1 row in my dataGridView after applying the filter, the error happens only when there is no row after the filter.
Please help me out, Thank you very much in advance!
Here is my answer, I don't really understand this but I've just tried and it works like a charm.
My rule is:
Before applying the filter, just SuspendBinding all controls from the BindingSource using SuspendBinding() method like this:
myBindingSource.SuspendBinding();
Now, just apply the filter normally like this:
myBindingSource.Filter = "filter expression";
Lastly, using ResumeBinding() method to re-bind all controls to the BindingSource like this:
myBindingSource.ResumeBinding();
And that's all. In fact myBindingSource has many controls which are bound to it. Maybe it's the reason but I still don't understand it well. I bet if the myBindingSource has only myDataGridView which it binds data to, there won't no need for all 3 steps above, just apply the filter (step 2) right when you need.
I hope this helps others which have encountered, are encountering and will encounter this problem. Again, I don't really understand why it works, and so I hope someone can explain it in a comment. I would really appreciate it. Thanks!
UPDATE
I've found that doing as I described above may have another problem in some case, the safest solution is:
SuspendBinding (as the above description, this is done using the method SuspendBinding() method of BindingSource), but the safest way is to set your DataSource to null.
Apply filter.
ResumeBinding (as the above description, this is done using the method ResumeBinding() of BindingSource), but the safest way is to rebind your control yourself (loop through each control and call Add method of DataBindings, remember to clear DataBindings first). You should have a method for doing this, because we may call to the re-bind method for many times.
And now I'm using this safer way, the way I mentioned before gave me another exception called "VersionNotFoundException" (There is no proposed data to access). The exception occurs at the line of ResumeBinding() call, there must some bug in that method. However I'm using a DataSet of multi-tables and switch between the tables on the same dataGridView. Again, this problem is still too complicated to dig into and understand at once.
The TRUTH
I've found that there is no need to suspend binding all controls before applying filter and resume bindings after that. My form has a control which is bound to a special column of the BindingSource (let's call it Column X), I still don't know why this column is special, I just doubt at it and just suspend binding it from BindingSource before applying the filter and bind it again after that. All other controls/columns are not involved.
The only thing I consider as noticeable here is:
=> My main table (Table 1) has a primary key column called A, this table has a foreign key called B which refers to the primary key column in another table (Table 2). The Table 2 has a foreign key which refers to the primary key column called C of another table (Table 3). And in fact, I had a query selecting all columns A, B, C (of course there are others not mentioned here). This relation is what I doubted at, but still unclear to me why and how it could raise error. If not using binding and assign/update all values manually, there would not any error. Binding is something sometimes really complicated.
because the there's nothing to be filtered that's why you get that error,
before you filter you dataGridView use this,
if (dataGridView1.Rows.Count > 0)
{
//do filter codes here
}
hope this helps.

ASP.net/C# newbie looking for help editing column width dynamically when data is retrieved

I've been messing around with this and have yet to find a clean solution. At the moment, I have a asp:DataGrid control on the aspx page (I am open to changing this). When I click a button, I retrieve a DataSet from a database and use a DataTable from the DataSet to fill up my DataGrid.
If my asp:DataGrid is named "tableData" and my DataSet is named data the following implementation will fill my grid successfully:
protected void renderData(object sender, EventArgs e)
{
DataSet data = hc.getDataSet();
tableData.DataSource = data.Tables[0];
tableData.DataBind();
}
But my column widths are not as wide as desired. I would like to look at all the data in each column of data.Tables[0] and choose my tableData column's widths accordingly.
I have tried many ways of accomplishing this and failed but here are my two main ideas and the problems I've encountered:
Solution 1: Alter column width after the DataBind(). I would use some type of code along the lines of
tableData.Columns[i].ItemStyle.Width = longestField;
The problem with this solution is the DataBind() seems to not have taken place yet and I get some null pointer like exceptions. I could do it after, but how would I know when it is done? Even if there was some event like AfterDataBind I would prefer not to use it because if I would have to determine what table I was dealing with in that particular function.
Solution 2: Create my own databind method and use that instead
The problem with this solution is I can't seem to add rows to tableData myself (I would expect something like a tableData.NewRow() function but I can't seem to find one fitting my needs.
I have also tried using OnDataItemBound function, but I realized I have know idea how to relate the DataGridItemEventArgs e back to datagrid's column collection.
I would appreciate some insight. Thanks in advance guys.
Calculating column widths is a tricky business, and is prone to glitches. I would suggest setting fixed widths for columns with a limited amount of data, and let the grid use percentage widths for the other columns.
For example, let's say you have a list of addresses.
Zip code should be less than 10 digits, so around 80px should be sufficient
City is not as limited, but 200px will probably do the trick
Street address could be really short or really long, so use a percentage width
If you're dead-set on calculating the column widths, take a look at this article:
http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q877q

ASP.NET Gridview, rows do not show if rows are less then page size

I seem to be running into an issue where my Grid-view doesn't display any rows when the number of items is less the page size (in this case 10), I'm using the object data source and at times it can return 1 or 7 for the number of items function call, which cause the grid view to not display anything at all. If I change the page size to 1 or 7 then the results will show. Anyone else run into this issue, any suggestions. Thanks.
Look in your code and post some code as well. It's 99.9% certain that it's a problem with your code - you have bug in your code somewhere, step through it.
Did you customize the paging ?

Categories

Resources