Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HI!
i have a data grid view that has as datasource one data table of dataset. when i try to add a new row to datatable sometimes datagridview is not displaying any rows. when it happens, it does it just from the application startup(form shows) i mean that the datagridview does not display lines from the beginning, not after displaying some and the rest are not being displayed .
I have to close the application to fix the issue.

plz any advice
Posted
Updated 13-Dec-12 7:50am
v2
Comments
[no name] 13-Dec-12 10:55am    
can you post a sample code about what you actually doing?
90jeri 13-Dec-12 11:48am    
i set the datasource of dg with
<pre>
dataset.Tables["BillLinesDt"].DefaultView.RowFilter = "ID = " + id;
dgBill.DataSource = dataset.Tables["BillLinesDt"].DefaultView;</pre>

i create new row with this :
<pre>
DataRow newRow = dataset.Tables["BillLinesDt"].NewRow();
</pre>
i set the values of each column
<pre>
newrow[0] = value1;
newrow[1] = value2;
</pre>


and then i add this new row to the datatable with this
<pre>dataset.Tables["BillLinesDt"].Rows.Add(newRow);</pre>

1 solution

You have RowFilter set to the dataset to filter out the data based on ID. remove the filter and check your display.

Check this line of code in your source.
C#
dataset.Tables["BillLinesDt"].DefaultView.RowFilter = "ID = " + id;
 
Share this answer
 
Comments
90jeri 13-Dec-12 13:18pm    
in dataset.Tables["BillLinesDt"] it keeps lines of bills so i need to get only the rows of a specific bill thats why i need that filter
Jibesh 13-Dec-12 13:21pm    
I understand that but since you said some of the rows couldnt added to the grid view can you also check the Id's of the newly added row.
Are you able to reproduce this problem all the time?> If yes for what value the grid doesnt display your data. You can use the 'Improve Question'link to update your questions if you want.
90jeri 13-Dec-12 13:54pm    
no i can't reproduce this problem it just happens some times. i know that rows are saved in dataset.Tables["BillLinesDt"] but they aren't displayed. so if i close the form and open it again everything is okay
Jibesh 13-Dec-12 14:03pm    
From the above code What i can read is you will see the problem(actually it's not a problem because we asked to do so by filtering the view) when records that doesnt matches the 'Id' value set to the filter. try to debug your code for what values it failed to display on the grid. you can use the System.Diagnostics.Trace class to log your output for debugging.
90jeri 13-Dec-12 14:19pm    
i've checked that is the same id ('id' is a foreign key to the id of the actual bill that is created so when i have only one bill it happened)

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