jog my memory on your annoying problem ? If it's deleting a a row according to its row index in theGrid but it's actually deleting another record or is it something else ?
Printable View
jog my memory on your annoying problem ? If it's deleting a a row according to its row index in theGrid but it's actually deleting another record or is it something else ?
It's not deleting the selcted row. It deletes some other row in the datagrid instead.
ljCharlie
Nothing wrong with your code when I tried it . I disabled the code inside clsDGComputer.vb and tried and no longer removing unspecified row . It seems to me that that code is a little bit buggy . Just add a row number in the txtRowNumber textbox and try it .
Have you tried sorting? Usually sorting is the cause of the problem.
ljCharlie
Yes , it's true . When sorting the grid ascendingly , it deletes rows from hightest point and vice versa . If you really don't need that sorting thingy, then I'll try to find a way around .
Thanks for the help. I think I figured it out.
ljCharlie
I hope so . Well , I was just trying to bind a context menu with the right click on any cell or row and select from the menu 'Delete' and it copy where the click is and perforum the operation . Happy coding ;)
Yes, that's a good idea. You're talking about right click on a row or cell and a menu showed up with options such as delete, update, edit etc.. right?
ljCharlie
Exactly . Your app may needs some additions like "Show tip" for the control bar , you can add more features also as context menu beside the bottons . Lastly , you are missing very important issue which distinct VB.NET lang from VB6 , it's OOP . You could have made your code re-usable in your future proj by putting these methods in a form that's not bounded to this proj only . You've done something cool , keep it up .
Thanks for help though. I know I still need a lot of the features...and perhaps when I'm at that stage I hope you'll still be here to answer some of my very basic questions.
By the way, what is OOP?
ljCharlie
It's Object Oriented Programming . It a way of organizing a program into logical components like Classes then Methods (Sub ,Functions and properties) . It makes a lot of sense esp in .NET . For example : A car obj (consider it as a program) . It may contains these objects : Wheels , engine , body , seats...etc . You can work on each of these objs separatly and isolated from the other obj . Then you can incorporate these objs (actually the methods in them) into the program to make the car work . It requires reading .
If that doesn't make sense (I'm sure it doesn't), then stop reading ....lol :D . There are thousands of pages on this topic .
I remember what OOP is now.
By the way, how do I refresh the datagrid to reflect what I have just inserted into the database file?
ljCharlie
I've tried refresh method but i doens't do it . Just call the same sub again (the sub you're using to iterate the Grid) .
Here's what I have tried:
DataGrid1.Refresh()
DataGrid1.DataSource = DataSet1.table1
DataSet1.Clear()
DataAdapter1.Fill(DataSet1)
But this is still not working. If I shut down the program and restart it again then it shows the latest records. But this is so inconvenience.
ljCharlie
Did you call the procedure itself rather than doing the above ? That's the way I do always .
The procedure that populate the datagrid is the same as above except the datagrid.refresh method wasn't included.
ljCharlie
How come you bind a dataset or whatever before you refill it ? Fill then bind the dataset .
I tried fill first then bind them but still not working. This time I called the initial procedure that fill the datagrid at the begining but still not reflecting the inserts.
ljCharlie
Since I still have the source code :o , In which part you're having troubles?
If you run the program, it is the fourth icon counting from left to right, which is the mnuInser_Click sub routine. This routine is the insert part. After you insert, the third icon from left to right is the datagrid that is not reflecting the inserting. The sub routine of that is mnuLog_Click.
ljCharlie
What a mess :p ! Dude , you have to re-code that really . It would be difficult to find bugs , continue developing it . No offense meant but that's just an advice . And one more thing , create your database objs with code , don't use controls objs .They Might be faster but buggy , slow things down , and rare you'll find someone to offer help and the most important is you lose re-usability of your code . Anyhow , I created a demo to show you how easy to solve your problem if it was written that way . It updates as soon as you add new record . Try it you might need to reconsider your code .
Thanks for the demo and your suggestion. Anyway, I figured out how to make it refresh now. I guess using those objects are easy but harder to debug. I have decided not to use this:
DataGrid1.DataSource = DataSet1.table1
DataSet1.Clear()
DataAdapter1.Fill(DataSet1)
Instead, I declared a variable to be a datatable and then fill that table with the records, and then bind that table to the datagrid. Somehow this way it works.
When I have more time on my hand I will convert that project to using code to populate the datagrid. It seems to me that by using code I can controll it better...I just thought that since VB.NET made it so easy to use those objects...I might try it...but it proves to be a pain to debug them.
ljCharlie