|
Hey thanks a lot!
I also thought in similar way that you thought. I still got some weird problems. I'm not allow to make the whole column unediatable. I can make only some of the cells of the column.
I'd appreciate if you could give me an idea how I can make a praticular cell unediatable rather than by whole coulumn. I'm sorry for my unclear questions
last time.
Thanks many for your help in advance
|
|
|
|
|
As far as I know, I am afraid you will have to make a choice; by the same principle you can determine the row index and make the row read only. So either make the entire row, or else the entire column read only (or the other way around). I have never tried myself, but perhaps you could investigate the possibility to determine the selected cell and try to make only that cell read only.
Another thing you could try is to make all rows read only, then when a user selects a row, make only that row editable, and during the same event make all columns except the selected cell's column read only again. I have no idea though whether this would actually work...
Good luck with it,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hey Johan:
Thanks a lot for good advice. Unfortunately, I was unable make a particular row uneditable. Below is my code.
Public Function CreateData(ByVal row As Integer, ByVal col As Integer)<br />
<br />
<br />
dt = New DataTable("sublayers")<br />
<br />
Dim i, j, k As Integer<br />
' col is used for determing column headers.<br />
<br />
dt.Columns.Add(New DataColumn("Sublayer No", GetType(String)))<br />
dt.Columns.Add(New DataColumn("Material Set No", GetType(String)))<br />
dt.Columns.Add(New DataColumn("Thickness (m)", GetType(String)))<br />
<br />
<br />
dt.Columns(2).ReadOnly = True<br />
<br />
<br />
<br />
For i = 1 To row<br />
<br />
dr = dt.NewRow()<br />
<br />
For j = 0 To col - 1<br />
<br />
<br />
dr(j) = " "<br />
<br />
<br />
Next<br />
dt.Rows.Add(dr)<br />
Next i<br />
<br />
'creating a datase<br />
Dim ds As New DataSet<br />
ds = New DataSet<br />
<br />
<br />
<br />
ds.Tables.Add(dt)<br />
<br />
'adding the table to dataset <br />
DataGrid1.SetDataBinding(ds, "sublayers")
I'm using this function to dynamically create datagrids. I neber got options to make rows uneditable. Can you advise how shall do this.
Thanks a lot for your help.
|
|
|
|
|
Hi,
My apologies, I misinformed you. I just mistakenly assumed there would be, but you are right, there isn't any direct option to make a row readonly.
The next option that comes to mind (and I don't see any alternatives), if you really need to lock only certain cells, is to set the readonly property of the datagrid to true, and bind the data from the selected datarow to regular textboxes or some other input system. This will allow you to control the input more easily, and to simply enable or disable a textbox when certain criteria are met.
Hope it helps,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hey:
Thanks a lot: I appreciate your time and help. I think I should think of making custom Datagrid control to add readonly features for each cell. Do you have any ideas how shall I do that?
|
|
|
|
|
I am sorry, I have no experience whatsoever in custom control making...
However there are plenty of people who have made custom datagrids, and I am sure Google could help you out with this subject. I seem to remember even seeing a few articles right here on the Code Project website with examples, etc.
Good luck,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
Hey friend>
Thanks, I appreciate your time and efforts. Thank your vey much for your suggestions.
|
|
|
|
|
Hello,
[VS 2005]
I have developed some code that uses a nested for loop. This code works the way it is supposed to. However, for maintaining this code I think i have not developed it in a efficient manor.
The way that the code works is that I have a database table and I am looping through the records finding the matching incidentID that have been delivered, so an e-mail can be sent.
As I am new to programming I am looking for a better way to do the same job.
I am sure there is a better technique for doing this, using some advance features of visual studio.
I am not looking for anyone to write me any code, just to review and give me an idea of another better technique.
Private Sub IncidentPartsArrivedEmail()<br />
Dim incidentID As Integer = 0<br />
Dim parts As List(Of String)<br />
Dim sentIncident As New List(Of Integer)<br />
Dim sendEmail As Boolean = False<br />
Dim orderID As Integer = CInt(Me.cboOrders.Text)<br />
<br />
Try<br />
'Loop through finding all the incidents that are ready to be sent.<br />
For Each outerRow As dsAddComponetAndEquipment.OrderDetailsRow In Me.DsAddComponetAndEquipment.OrderDetails<br />
'check to ensure that all the orders are for the same order.<br />
If (orderID = outerRow.OrderID) Then<br />
If (outerRow.Status = "Delivered") Then<br />
incidentID = outerRow.IncidentID<br />
'Ensure that the incident is not going to be repeated again.<br />
If Not (sentIncident.Contains(incidentID)) Then<br />
parts = New List(Of String)<br />
'Add the incident to the array to check later that this incident has already been done.<br />
sentIncident.Add(incidentID)<br />
For Each innerRow As dsAddComponetAndEquipment.OrderDetailsRow In Me.DsAddComponetAndEquipment.OrderDetails<br />
'check to ensure that all the orders are for the same order<br />
If (orderID = innerRow.OrderID) Then<br />
'Only the incidents with the same incidentID <br />
If (innerRow.IncidentID = incidentID) Then<br />
If (innerRow.Status = "Delivered" AndAlso innerRow.EmailStatus = "Waiting") Then<br />
parts.Add(String.Format("{0} - {1}", innerRow.Manufacturer, innerRow.Model))<br />
sendEmail = True 'Everything ok so send the email<br />
Else<br />
sendEmail = False 'Not all parts have been delivered <br />
Exit For<br />
End If<br />
End If<br />
End If<br />
Next innerRow<br />
If (sendEmail) Then<br />
Me.SendPartsEmail(Me.EngineersEmail(incidentID), parts, Me.CurrentUsersEmail())<br />
Me.TA_OrderDetails_dsCodeRed1.UpdateEmailSent(incidentID, orderID)<br />
End If<br />
sendEmail = False 'Set the flag back to false again to start the new incident<br />
End If<br />
End If<br />
End If<br />
Next outerRow<br />
Catch ex As Exception<br />
MsgBox(ex.Message)<br />
End Try<br />
End Sub
|
|
|
|
|
Looks to me like you're iterating through a data set when you could write a stored proc or SQL that does those comparisons in the data layer.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Try using a DataView with RowFilter.
So something like
dim dv as DataView = Me.DsAddComponetAndEquipment.OrderDetails.DefaultView
dv.RowFilter = "columnname = 'somedata'"
Once you have set the rowFilter you will only see the datarowview that match that filter. You would need to set the rowfilter back to "" to get all rows again.
Hope that helps.
Ben
|
|
|
|
|
I am using Visual Basic to make a website and I want a user to be able to enter things in a Textbox and have that information put into access. I am using a Inset statement but it does not work. I am useing:
INSERT INTO Results
(Application_contact)
VALUES (AC.[text])
And it does not work does anyone have any ideas how i can have the textbox information put into a access?? PLEASE HELP!!
|
|
|
|
|
Ronak085 wrote: INSERT INTO Results
(Application_contact)
VALUES (AC.[text])
What is AC, and how are you using this code, in Access ? What does 'does not work' mean ? Does it compile ? What does it do ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
AC.text is a textbox that a user can input information and I would like that information to be put into a access database.
|
|
|
|
|
Am i correct in thinking Application_contact is a field name and AC.[text] is the text within a textbox named AC?
If i am correct then the SQL code is wrong. This part
Ronak085 wrote: VALUES (AC.[text])
will do nothing. For example if you wanted to insert the text 'AC.[text]' then the code would need to look like:
VALUES ('AC.[text]') (note a string literal must be enclosed '')
if AC.[text] is a variable (which i think it is) it needs to be:
VALUES ( '" & AC.[text] & "')
string variables must be enclosed '" & & "'
Numerics are " & & "
and with Access dates are #" & & "#
#EDIT#
And before anyone else nags me about it.
I know parameterized queries are better.
Jon
|
|
|
|
|
Since AC is the text box name and i want to convert what the user inputs into the text box to be brought to the access database. None of the follow work for me.
|
|
|
|
|
you should try AC.value, i programming in vba of access 2003 and i haven't access to control.text except if he has focus, i use value property to get text from text field.
|
|
|
|
|
In excel, I have listboxes (validation) in column A, and columb B. The ones in A work. I wrote code to check to see when there's a change in any item in A, and if the user hit 'No' on the MsgBox, then the change would be 'Undone' (ie. managed to use Undo in VB code).
My problem is, I'm using virtually the same code for column B. However, columb B's list items are a validated list depending on what was selected in A. Whenever a change is made in B, and the user hits no, Undo is NOT executed. Any ideas as to why this is happening? Here's a sample of the code that is working for A: (Note that the code I have for B is the exact same with different Range references)
'''Code start''''
Public undoCheck As Boolean
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If undoCheck Then
'do nothing
undoCheck = False
Else
Dim i As Integer
Dim rowNum As Integer
i = 10
While i < 85
If (Target.Address = "$A$" & i) And (Cells(i, 2).Value <> "" Or Cells(i, 3).Value <> "" Or Cells(i, 4).Value <> "" Or Cells(i, 5).Value <> "" Or Cells(i, 6).Value <> "" Or Cells(i, 7).Value <> "" Or Cells(i, 8).Value <> "") Then
If MsgBox("You are changing Element Data. Related Element Data will be removed but calculation data will remain. Do you wish to continue?", vbYesNo) = VbMsgBoxResult.vbYes Then
'clear values
Range("B" & i).Value = ""
Range("C" & i).Value = ""
Range("D" & i).Value = ""
Range("E" & i).Value = ""
Range("F" & i).Value = ""
Range("G" & i).Value = ""
Range("H" & i).Value = ""
Range("I" & i).Value = ""
'highlight colours
Range("C" & i).Interior.Color = vbYellow
Range("D" & i).Interior.Color = vbYellow
Range("E" & i).Interior.Color = vbYellow
Range("F" & i).Interior.Color = vbYellow
Range("G" & i).Interior.Color = vbYellow
Range("H" & i).Interior.Color = vbYellow
Range("I" & i).Interior.Color = vbYellow
undoCheck = False
Exit Sub
Else
undoCheck = True
If Application.CommandBars.FindControl(ID:=128).Enabled = True Then
Excel.Application.Undo
End If
Exit Sub
End If
End If
i = i + 1
Wend
End If
End Sub
''''Code end'''''
|
|
|
|
|
I have a program that I have written that uses its main form to show buttons which show the status of devices. These button have their own class (inherting the button class) and are run as their own threads and can update themselves as required.
What I want to do, is to make the form become the TopMost window when one of the buttons indicates an error condition. I can make the button threads modify a master variable of the form, and that works. But when I then also try to make the form TopMost (TopMost=True) (actioned by a button thread) is does not get remembered. E.G if a button thread calls the main forms subroutine :-
Public Sub attention()
SyncLock myObjLock
If need_attention = False Then
need_attention = True
TopMost = True
End If
End SyncLock
End Sub
need_attention gets updated to False but TopMost never happens. If I call this from the main form routines it seems to work, just not when a thread calls the routine.
I'm not sure if I'm missing something simple, hopefully I am.
Please help
Thanks
Nigel
|
|
|
|
|
Have you set a breakpoint to make sure the TopMost call occurs ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
The TopMost call gets called and is set to true. But when I set a breakpoint further on when something else happens and I look at the TopMost value, it is False and so the setting is never held. I never set it back to False so it can't be holding its value (well its not being set properly I guess).
Its confusing !!!
Nigel
|
|
|
|
|
Well, it works and it sticks. The only three things that can change that are:
1: You change it back to False.
2: You create a new instance of your form somewhere along the way and assign it to the same variable, thus giving the appearance that it didn't stick.
3: Some other form set TopMost to True somewhere else in your app.
|
|
|
|
|
|
uk_nbb wrote: and are run as their own threads
I am not sure what you are saying here, are you having some other thread create
and handle a Button ?
All Controls require they be touched only by the thread that created them,
which in practice means everything gets created and touched by the main thread
(aka GUI thread only), since thats where your first Form gets created, and normally
everything in one way or another connects to it.
There are a few properties/methods that dont have to obey this rule; mainly
InvokeRequired and Invoke() and its exactly these that you must use to
let another thread do something to a Control it did not create.
If you dont follow the rules here, on old .NET (prior to 2.0) it may or
may not work, typically it will suddenly ignore you or freeze, show a white
menu bar, things like that. Since 2.0 it will throw an InvalidOperationException
except when you have set CheckForIllegalCrossThreadCalls=false, which is
considered bad practice and brings you back to the 1.x behavior.
Hope this helps.
|
|
|
|
|
I think Invoke() may be my missing link.
I will read all about it and have a go.
Thanks
Nigel
|
|
|
|
|
i want to make a textbox that would only accept numbers as an input...
can you please give me sample codes. thanx!
i am using vb.net 2002 (desktop application)
|
|
|
|