Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid - Databound issue

Status
Not open for further replies.

tpbjr

MIS
Oct 8, 2004
120
US
Hi,
I have been struggling with this problem for a week now. I have a login table that has a relationship of one to many with a look up table.
I want the data grid to be bound to the look up table (tblDoctorType). This table only has AutoID, UserID and DoctorType fields.

Lets say that the user with a UserID of 3 opens the form with the datagrid. The only way I can add a new record to the grid successfully is if I manually fill in the value 3 for the UserID field. I want to somehow hide that column on the grid and programattically fill in the field of the dataset associated with the grid with the value of the currently logged in user. In this example that would 3. I am thinking if I could do that then when I issue the m_Adapter.update(m_dataset) command it should save the record successfully.

Any ideas how I can get this to work or where I can get an example of what I am trying to do.



Thank you for all your help

Tom
 
Oh, I forgot to mention that this is a Windows Form with a datagrid on it, not ASP.NET.

Clearer picture of what the grid looks like

AutoID LoginID DoctorType
-----------------------------
1 3 Primary Care
2 3 Orthopedic
3 Add this record

The first two records are already in the database.
When I type the third record and close the form
My update method saves the record to the database just fine. When I open the form back up it looks like this.

AutoID LoginID DoctorType
-----------------------------
1 3 Primary Care
2 3 Orthopedic
3 3 Add this record

I really want to be able to only have the user see the DoctorType. The AutoID field seems to work automatically behind the seens. I need to programmatically get the UserID (3) in the record of the Dataset ( think that is what I need). I have a global variable at my finger tips that stores the UserID when they login.

Thanks again.


Thank you for all your help

Tom
 
It appears as though I have answered my own question with the following code/event usage. But now I would like to hide column 1 and column 2 (AutoID and LoginID) as long as it does not disrupt the new code listed below. Can someone please tell me how to hide specific columns in a datagrid?

In addition, how can I get the focus to the last row position in the grid when the form first opens.

Private Sub dgDoctorType_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgDoctorType.CurrentCellChanged
Try
dgDoctorType.Item(dgDoctorType.CurrentRowIndex, 1) = gUserID_Number
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Thank you for all your help

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top