DataGrid Column id's - vb.net

Quick one chaps,
If I have a datagridview control, lets call it 'tasklist'.
When I populate it, there are 3 columns, 'id', 'tasktitle' and 'owner'.
I dont want to show the 'id' on screen so I simply do:
tasklist.Columns(0).Visible = False
Thats all good and the id column is not visible.
Does this then mean in terms of referencing the column numbers that 1 becomes 0 and 2 becomes 1?
or does the non-visable 'id' column retain the 0 id and 1 and 2 also stay the same?
Thanks!

This is not answer to question - just "better practice" for not using indexes(hard-coding).
Create predefined columns through designer.
Give a name for every column(for example: task_id, task_title and task_owner)
Then through designer you can set Visible property task_id.Visible = false(or in code)
Then in code(Load event) add mydatagridview.AutoGenerateColumns = false - this will prevent datagridview generate columns
After this you can use your column without doubt about indexes
mydatagridview.Rows(0).Cells(task_owner.Name).Value = 'testowner'

Related

SSRS Drop Down List Problems

This questions kind of carries on top of the previous question I asked. Anyhow, I am creating this report in Report Builder 3.0. I have about 5 tables, 1 - 5. I have a drop down list that displays the table names 1-5. However, I want to regroup some of the tables together. For instance, the upgraded drop down would look something like this:
Drop Down List:
One&Two
Three&Four
Five
So If i were to click on One&Two, tables 1 and 2 would display while the others would stay hidden.
((CASE WHEN 'All' = 'All' THEN 1
WHEN #Input = 'One&Two' THEN 1
When #Input = 'One&Two' THEN 2
ELSE 0 END) = 1)
Using the above case doesn't do anything.
In my tablix properties I have the following command:
=Parameters!Input.Value <> "One&Two" AND Parameters!Input.Value <> "All"
This doesn't give me the table nor the columns, however doing this for a textbox it works. Going back to my original problem, how can I display 2 tables using only one drop down value from the list and hide the rest. I tried doing the multi select, but that didn't work out so well, because of the visibility issue.
You are referring to the hidden property evidently. Can you check and make sure you should be using label to compare?
=Parameters!Input.Label<> "One&Two" AND Parameters!Input.Label<> "All"

How to Disable DataGridView from automatically reordering columns when bound to dataset table

I have a datagridview and I am binding to a dataset object that was created with the visual studio designer.
As a simple example:
My query of a SQL database returns my columns in order : ID, NAME, GRADE - just fine, if I query manually and return and bind no problems columns show up in the order they were returned from the query.
However I am required to use the dataset object. When the DataGridView is bound to the table inside the dataset (even though the table columns are in the right order ) the datagridview decides on its own to reorder the columns!! Aaargh!!
How can I prevent this ugly behavior ?
I am not looking at naming my columns and setting the ordinal positions as is posted here:
Disable datagridview automatic ordering VB.NET
That 'answer' does not prevent the behavior but forces known column names[Hard Coding] and setting ordinals for any and all datgridviews.
CODE EXAMPLE:
Dim dt As appDataSet.booksDataTable = New appDataSet.booksDataTable
BooksTableAdapter.FillByRecipeID(dt, ID)
' This just checks for a particular field and uses a drop down instead.
' You can exclude it the behaviour is the same.
dgvExample.AutoGenerateColumns = False
If dgvExample.Columns.Count < 1 Then
CreateDataGridColumns(dt)
End If
dgvExample.DataSource = Nothing
dgvExample.DataSource = bsBooks

Display text corresponding to Combobox selection in Microsoft Access 2010

I have a contact form and one of the fields in a the form is a Contact_Type_ID. This field is a number field which also corresponds to a text field in another table (e.g. 1 = expatriate).
When I cycle through the contacts, their Contact_Type_ID is 1, 2, 3... instead of Non-profit, CEO, Vice-president, etc. This is a problem because one has no idea what number 3 means.
I would like to a combobox that only displays the corresponding text.
I can't get the two columns and 0;1 format to work. My hunch is that it's because I'm drawing information from two different tables. I can generate the correct list, but then the main entry doesn't change as I cycle through the contacts to reflect the current contact's [Contact_Type_ID].
I can't edit any of the current tables because I am supposed to apply this application to a much larger scale database.
I also tried setting the SQL for the row source:
'Populate the connection combo box '
Dim typeSQL As String
typeSQL = "SELECT DISTINCT Contacts.[ContactTypeID], Contact_Types.[ContactType] " & _
"FROM Contacts, Contact_Types " & _
"ORDER BY Contact_Types.[ContactType];"
Me.cbo_ContactType.RowSource = typeSQL
However, I then have the same problem: the combobox won't update as I cycle through the contacts. I don't understand the difference between the rowsource and the controlsource. I feel that this distinction might be key here.
Assuming I understand correctly:
In the combo box properties, go to the Data tab.
Set the Control Source to Contact_Type_ID.
This means that when you go through the records, the combo box will correspond to the Contact_Type_ID field from your data.
Set the Row Source to "SELECT Contacts.[ContactTypeID], Contact_Types.[ContactType] FROM Contacts, Contact_Types ORDER BY Contact_Types.[ContactType];"
The Row Source indicates the data that the combo box has access to, which will help it determine how to display the control source value.
Set the Bound Column to 1
Set Limit to List to Yes
Now in the Format tab. Change Column Count to 2.
Next set the column widths to the 0;1 you mentioned in your question.
Now try looking at form view, and it should behave as you expected.
If it does not work, create a new control with these instructions.
As I understand your question, you have a form with contacts based on a table Contacts and that table contains a field called either Contact_Type_ID or ContactTypeID. You wish to display the description of the contact type from a table Contact_Types.
You do not need to join tables for your combo, it should be very simple. The key, as you suspected, is the Control source, which is the property that relates one table to another.
Control source : ContactTypeID '' or Contact_Type_ID, choose from the list
Row source : SELECT ContactTypeID, ContactType FROM Contact_Types ORDER BY ContactType
Bound column : 1
Column count : 2
Column widths : 0,2
As an aside, you can join tables in a combo and still set the first column to 0 and it will still work, it is all in the correct set up.

How to make a drop down list (list box)in an MS Acess Query with values from two different tables

I need the drop down box above to display the date as shown and the ClassTypeDesc as you can see above the dropdown list shows 1/12/2010 twice. They have different ClassTypes Assigned to them.
The drop down list should show:
1/12/2010 ACLS-I Day One AM
1/12/2010 ACLS-I Day One PM
I need to know the statement to put in the Row Source Box on the lookup tab in the Field Properties to make this work.
Related Question on Making a drop down list
There's no need to concatenate the two columns. Based on the diagram, the SQL for your lookup combo box should look like this:
SELECT tblClassSession.SessionID, tblClassSession.Date, tblSessionType.ClassTypeDesc
FROM tblClassSession INNER JOIN tblSessionType
ON tblClassSession.SessionTypeID = tblSessionType.SessionTypeID;
Then in the properties for your lookup combo box, change ColumnCount to 3, and Column Widths to 0 (if you want to size the other columns, change Column Width sto something like 0";.75";1.5", and the List Width property to 2.25").
I may have gotten some of the field names wrong, but that's the basic idea.
(also, you probably really ought to rename tblClassSession.Date to tblClassSession.SessionDate so you don't run into problems with the fact that Date is a reserved word)
As you already have the right number of rows, you just need to concatenate enough fields to make it more useful, so your query would be something like:
SELECT c.Date + ' ' + s.ClassTypeDesc AS YourFieldName
FROM...

What is the purpose of BOUND COLUMN property of listbox in MS Access?

What is the purpose of BOUND COLUMN property of listbox?
The bound column is a number that represents what column from the row source will be used to set the value of the Control Source (if the list box is bound).
Note that you can’t use a column name here. So you don't set the bound column to a column name, but you must use a column number.
Another issue here is that the column number starts at 1 (not zero). Note that OFTEN the 1st column length is set to zero. That allows you to have a list box with something like
select PartNumber, PartDescripton from tblParts
The list box will display the part description, but if you set the bound column = 1, then the listbox will return the PartNumber despite the fact that the listbox is displaying Descriptions (since you set the length of the 1st column = 0. If you set the bound column = 2, then the listbox will return description. Note that you can grab any column value from the list box by using
([lstBox1].Column)
Note that in the above, the column feature is zero based. So, 1 = 2nd column
It's the column of the data set that is used to set the value of the listbox. For example, if it's bound to a dataset with the query:
select firstname,lastname,userid from users;
then setting the bound column to userid (3 in the above example) will cause the user ID information to be returned as the listbox value.
A bound column is the data that the form is going to save. For instance, if you have a list box or combo box that lists employeeID and employeeName and you set the bound column to 0, the form will save the employee ID number from
the selection and insert that value into the corresponding table.
You can test which value you are referencing this using this vba:
Private Sub ComboBoxName_AfterUpdate()
MsgBox ("bound column is: " & Me.ComboBoxName.BoundColumn & ". value is: " & Me.ComboBoxName.Column(0))'change 0 to whatever number column is bound
End Sub
The bound column rule applies even if the first column is hidden on the form. For instance, the user could select "Mike Jones" from the employee list, but the form is going to save Mike Jones' employeeID for data uses (this ID could be stored in a table of sales records, etc.).