DataGrid Help

There a many posts about DataGrid and I have been searching and reading for days and have made some progress with my program. There are a couple of things I want to do that I can't work out.

When I enter a new row of data into my datagrid I want to jump from the current column to the next column when I click the enter key. I have tried a simple "DataGrid1.Row = DataGrid1.Row + 1" which does move the cursor to the next cell but for some reason it leaves the previous columns input in the cell and takes the newly input value to the next cell. There must be a simple way of doing this?

When the datagrid is first filled with data from my database I also want to show another row across the bottom which will show totals of each column value. They all have numeric values in them. Is this possible?

I also want to add another column that is not part of the database table that will show a value by taking the database values in the same row and applying a formula. Is this possible?

Hope I have explained myself OK and any help will be greatly appreciated.

Comments

  • Ok, I am not too sure if I understand everything here, so we will take this problem 1 step at a time.

    First problem, you want to move to next column when the enter key is pressed. Ok, you have the right idea, but the code you are using moves to the next row, not the next column. Use the columns property instead. Another thing, there should be a property that will allow the tab key to be pressed to switch columns I believe. This may make it simpler.

    Second problem, the data you enter in the first column is being carried to the next column instead of overwriting the original value and sending focus to the next column. I think you may need to take a careful look at your code for this. I imagine you have used an instruction to move to the next column first. Be careful which event you place the code in.

    Third problem, you need the totals to appear at the bottom of the grid. There are so many ways to go about this, one way is to just use labels and keep it separate from the grid, that way any data can be looked at as well as the totals at the same time. Another option (if you want the totals located on the datagrid) would be to just add a new row. To do this you need to declare a datarow object, set it to datagrid.newrow, then add the column totals to the datarow, add the datarow to the datatable (use the Add method to attach the row), then release the resources.

    Fourth problem, you need another column. This is very possible, but I would recommend using the datatable object. This way you can define all the columns that will appear on the datagrid. All you need to do is declare the datatable, fill it with values, and use the datatable as the datasource for the datagrid instead of using the database. You will of course have the values from the database because you will fill them in the datatable, as well as the calculated column.

    Hope this helps you a bit, if I was not clear just put another post or email me at [email protected]
  • : Ok, I am not too sure if I understand everything here, so we will take this problem 1 step at a time.
    :
    : First problem, you want to move to next column when the enter key is pressed. Ok, you have the right idea, but the code you are using moves to the next row, not the next column. Use the columns property instead. Another thing, there should be a property that will allow the tab key to be pressed to switch columns I believe. This may make it simpler.
    :
    : Second problem, the data you enter in the first column is being carried to the next column instead of overwriting the original value and sending focus to the next column. I think you may need to take a careful look at your code for this. I imagine you have used an instruction to move to the next column first. Be careful which event you place the code in.
    :
    : Third problem, you need the totals to appear at the bottom of the grid. There are so many ways to go about this, one way is to just use labels and keep it separate from the grid, that way any data can be looked at as well as the totals at the same time. Another option (if you want the totals located on the datagrid) would be to just add a new row. To do this you need to declare a datarow object, set it to datagrid.newrow, then add the column totals to the datarow, add the datarow to the datatable (use the Add method to attach the row), then release the resources.
    :
    : Fourth problem, you need another column. This is very possible, but I would recommend using the datatable object. This way you can define all the columns that will appear on the datagrid. All you need to do is declare the datatable, fill it with values, and use the datatable as the datasource for the datagrid instead of using the database. You will of course have the values from the database because you will fill them in the datatable, as well as the calculated column.
    :
    : Hope this helps you a bit, if I was not clear just put another post or email me at [email protected]
    :


    Thanks for the help. I am a bit lost here and I am going to work it through a bit at a time. I am going to worry about the moving around stuff later, once I have the datagrid looking the way I want. I think the datatable idea sounds good, filling it with the data from my database and setting it as the datagrid datasource. I am unsure about declaring a datatable and loading it with my recordset. Can you point me to some examples of this? Thanks again.
  • Ill make you a sample to view, kind of busy right now so I will post it sometime within the next 24 hours.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories