-1

I have a question and can't seem to find the solution. I have datagridview columns with multiple types:

  • Textbox
  • Checkbox
  • Button

I used dgv1.AllowUserToAddRows = true;. And the problem is new row doesn't show when the button column is clicked. For textbox and checkbox columns, it is working.

Please help me on this.

Thanks.

Luthfi
  • 478
  • 1
  • 3
  • 16
newbie
  • 9
  • 7
  • The common issue with DGV is it doesn't always repaint when new data is added. So the trick is to set the datasource to null : datagridview1.DataSource = null; DataGridView1.DataSource = dt; – jdweng Nov 04 '18 at 09:54
  • @jdweng- already tried setting the datasource to null but still doesn't show – newbie Nov 04 '18 at 12:38
  • Count the number of rows in DGV before and after you insert and see if the number increases. The added row may be sort and put in middle of DGV. – jdweng Nov 04 '18 at 12:53
  • To further describe: there is already one row visible and this is the row with asterisk (for edit). Now there are multiple columns with different types. Whe clicking checkbox column,new row appears. When editing textbox column,new row also appears at the bottom BUT when button column is clicked,new row doen't appear at the bottom. I need the new row to appear at the bottom when buttoncolumn is clicked. – newbie Nov 04 '18 at 13:08
  • Why do you need it at the bottom? Is data going into a database? – jdweng Nov 04 '18 at 13:12
  • Needed to be at the bottom as this is more convenient and standard. Yes,this will be saved in database. – newbie Nov 04 '18 at 13:15
  • The query to the database doesn't return data in the same order it is inserted. The query does the search of the database using parallel processes so the results are not sequential. You have to add an OrderBy to the query to make sure you get the results in order. – jdweng Nov 04 '18 at 13:19
  • Yes,i agree with order. But the issue is more on adding record on gui. Need to have the same behavior with other datatype columns. – newbie Nov 04 '18 at 13:26
  • Copying should work as long as you rebuild the project. I would delete the bin folder in the project. then double click on the .proj file in the project folder to open VS. – jdweng Nov 04 '18 at 19:34

1 Answers1

-1

Just found an alternative solution. Instead of Edit Row by having dgv1.AllowUserToAddRows = true, i have inlcuded another button for dgv1.rows.add(). This could already work. Thank you.

Here is the link:Rows cannot be programmatically added to the datagridview's row collection when the control is data-bound

newbie
  • 9
  • 7