I have a DGV which is part of an inventory system. I have several columns but the ones i need to resolve are Quantity, Name and Plural Name. essentially if quantity is 1 i need to display the Name data if greater than one the plural data. Is this possible? would i need to resolve this earlier in the process (the data is extracted from an xml file using LINQ to bind it to a rowObject) or can i do this with the completed dataset, say by hiding the Name and Plural Name colums and creating a custom column? ideally i would like to keep the data untouched.
If debugging is the process of removing bugs, then programming must be the process of putting them in.
Ok i have answered most of my question, i have hidden the Name and Plural Name columns and created a new Column Item, how now do i fill the new custom column with the data based on the if statement?
If debugging is the process of removing bugs, then programming must be the process of putting them in.
You're talking about a custom type (RowObject) but then you mention a DataSet, so I'm not sure what your grid is bound to. If the data source is a DataTable then you can add an extra DataColumn and set its Expression property to calculate the value based on other columns.
I am confused over this :s what i have done is bound the data to the RowObject in data sources, i then used the DGV form designer to fill the grid using this source. As you know this project takes data from a linq query binds it to a list of this object and then (now) binds this object to a datasource. I feel like i'm in some kind of warped space with all this. what would be the correct way to implement this based on the following criteria
1/ The data is extracted from xml into a LINQ query.
2/ This data is used in other methods within the main application (check to see if sufficient quantities exist and wether a product ID exists)
3/ The data populates a DGV which should be sortable ideally by any column (as it stands i am sorting by either Cost or Quantity using a few radio buttons on the form)
4/ The data is repopulated when new stock arrives
I presume that i have gotten myself in a cant see the wood for trees state of mind any pointers would be appreciated to get this done in the simplest way.
P.S. i dont mind rewriting the entire process if it does what i need
Last edited by Megalith; Jan 12th, 2010 at 07:51 PM.
If debugging is the process of removing bugs, then programming must be the process of putting them in.
Part of the confusion is due to terminology. You're using terms that have specific meaning where that meaning doesn't apply and, as such, I don't really know what you mean and you probably don't either. For instance, data isn't extracted INTO a LINQ query. The query does the extracting and then returns the results as an IEnumerable list. Also, your LINQ query doesn't bind anything. The query creates and populates objects and then returns them in a list, which you then bind to your control(s).
I think you need to explain exactly what you've done, fully and clearly. You say this:
what i have done is bound the data to the RowObject in data sources
I don't really know what that means. RowObject is a table in a typed DataSet? A row in a table in a typed DataSet? Something else?
OK, things are clearer now. Yes, that sounds fine. You certainly can add an unbound column to a bound grid. You'd then handle the appropriate event, probably CellValueChanged, to set the value in the unbound column based on values in the bound columns.
Re: [RESOLVED] DGV display a column based on logic.
Ok this is hurting my head and i should be in bed. I dont seem to be able to get how to determine the value. I tried datagridview1.Item("Item", e.RowIndex).Value = "Blah" which i presumed would fill all the values of the Item column with Blah but i got a runtime error...
An error occurred creating the form. See Exception.InnerException for details. The error is: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
which is in the line where the DGV is populated with the list, but is obviously within my CellValueChanged event
Further i was unable to work out how to access the hidden Name and PluralName columns so as to determine the value for Item based on the value of Quantity.
Google for help with this has been fruitless with most of it referring to Net2003 and 2005 neither of which are the same as in 2008 by all accounts and were misleading to say the least one example said to use row[x].column[y] so i'm going to walk away from it before my head explodes
Something i guess would work would be to override the paint event but i think that is ott for my needs and would anyway end with the same problem of determining where the data is.
If debugging is the process of removing bugs, then programming must be the process of putting them in.
Re: [RESOLVED] DGV display a column based on logic.
It's a matter of a bit of reading, experimentation and debugging. I didn't know the exact answer to your problem so I took a look at what events the DGV had available that might be relevant, wrote some code and debugged to see what happened.