I have a data model in PowerDesigner. I wrote a vba-script that changes the description of a column to the value of the comment of the column. It does well. When I look at the column-properties I can see the new description. The problem is, that the new description does not appear in the table-overview. Only when I open the column-properties and close it with the ok-button, the new description appears in the table-overview. I have a lot of columns in my model, so... has it something to do with the object-hierarchy in PowerDesigner? My script:
option explicit
Dim kind, name, obj, c, a
kind = InputBox("(T)able or (V)iew")
name = InputBox("Enter name")
If kind = "T" Then
Set obj = ActiveModel.FindChildByName(name, cls_table)
ElseIf kind = "V" Then
Set obj = ActiveModel.FindChildByName(name, cls_view)
End If
For each c in obj.columns
c.SetAttribute "Description", c.comment
Next
Related
I am using Grid from devExpress to display some data from database, I also implemented RepositoryItemLookUp because I needed to see some values in my column as dropdowns and here is the code:
`Dim riLookup As New RepositoryItemLookUpEdit()
riLookup.NullText = String.Empty
DataTableDobTableAdapter.FillDob(Me.DsOrders.DataTableDob)
riLookup.DataSource = Me.DsOrders.DataTableDob
riLookup.ValueMember = "ID"
riLookup.DisplayMember = "TITLE"
riLookup.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup
GridView1.Columns("Code").ColumnEdit = riLookup`
Here is the photo of that what I am talking about:
I'm wondering how can I handle this repositoryitemlookupedit so if whatever is choosen there I might change value of another column from N to D as I highlighted in a image.
Maybe I can write condition in my appereance-> format condition section.
Whatever I need to change another columns value if something is choosen from this repositoryitemlookupedit, whatever I'm really struggling with this because I've never used before v.b neither devexpress.
Thanks guys
Cheers!
AFTER ALEX HELP:
I put a breakpoint there to check what is e.NewValue and I saw it is acctually ID from database, because I choosed MCI which has ID 1000097 and when breakpoing hitted I catch that Id but with suffix :"D" at the end.. why is that?
You could handle the RepositoryItemLookupEdit.EditValueChanging event.
Just add an event handler to your existing code:
Dim riLookup As New RepositoryItemLookUpEdit()
riLookup.NullText = String.Empty
DataTableDobTableAdapter.FillDob(Me.DsOrders.DataTableDob)
riLookup.DataSource = Me.DsOrders.DataTableDob
riLookup.ValueMember = "ID"
riLookup.DisplayMember = "TITLE"
riLookup.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup
GridView1.Columns("Code").ColumnEdit = riLookup
'Add this line:
AddHandler riLookup.EditValueChanging, AddressOf repItem_EditValueChanging
Now just handle the event and do your logic to set the "N/D" column:
Private Sub repItem_EditValueChanging(sender As Object, e As ChangingEventArgs)
If e.NewValue > -1 Then 'any ID given => "N"
GridView1.SetRowCellValue(GridView1.FocusedRowHandle, GridView1.Columns(6), "D")
Else
GridView1.SetRowCellValue(GridView1.FocusedRowHandle, GridView1.Columns(6), "N")
End If
End Sub
(I assumed column 6 from your screenshot).
P.S.: One thing that I couldnĀ“t find in your code but which is neccessary to get a repository item to work properly is to add it to your GridView RepositoryItems collection like:
GridControl1.RepositoryItems.Add(riLookup)
I'm working on a Sindows Forms application to help keep inventory of some scanners. I'm using Linq2Sql, each table has an id column. On my repair history form. I'm trying to use the serial number from the inventory table so it goes to the database and looks up the sID from the table and it returns the correct value, but when I go to send all the entered data to the history table it gets a null reference exception.
Dim db As New DataClasses1DataContext
Dim rep As Scanner_Repair_History
Dim scan = (From Scanner_Inventory In db.Scanner_Inventories Where scannerid.Text = Scanner_Inventory.SN Select Scanner_Inventory.SID).FirstOrDefault
rep.SID = scan
rep.Date_Broken = datebroke.Value
rep.Description = description.Text
rep.Send_Date = senddate.Text
rep.Recieve_Date = recievedate.Text
rep.Cost = cost.Text
rep.PlantID = plantid.Text
rep.BID = brokenid.Text
rep.RMAnumber = rmanum.Text
db.Scanner_Repair_Histories.InsertOnSubmit(rep)
db.SubmitChanges()
is that me but you didn't instanciate your "rep" variable
You don't have a defined object for placement with a 'new' keyword but I am also curious if it is a system.type.
Update based on Jinx88909
You may be returning an entire POCO Object that may be null and have a null property. You can adjust this most times by doing a null condition if you are using .NET 4.5 and up. '?.' operator.
Dim db As New DataClasses1DataContext
'I need to be a new object and not instantiated as Nothing
Dim rep As New Scanner_Repair_History
'You have the potential for a nothing value here as 'FirstOrDefault' includes a potential Nothing'.
'I would get the entire object and then just a property of it after the fact
Dim scan = (From Scanner_Inventory In db.Scanner_Inventories Where scannerid?.Text = Scanner_Inventory?.SN Select Scanner_Inventory).FirstOrDefault?.Sid
If scan IsNot Nothing Then
rep.SID = scan 'Could you maybe want scan.Id or something similar?
rep.Date_Broken = datebroke.Value
rep.Description = description.Text
rep.Send_Date = senddate.Text
rep.Recieve_Date = recievedate.Text
rep.Cost = cost.Text
rep.PlantID = plantid.Text
rep.BID = brokenid.Text
rep.RMAnumber = rmanum.Text
db.Scanner_Repair_Histories.InsertOnSubmit(rep)
db.SubmitChanges()
Else
Console.WriteLine("I got nothing for you with the inputs you put in!")
End If
I'm working on program which uses xpo collection to get and update data from and to database. I setted up lookupedit to get data from another database(country name) I would like another lookupedit (country code) to be filled in automatically after country name is selected.
Here is XPO collection:
Private Countries As New XPCollection(Of clCountry)(UOW)
and here is lookup code:
CountriesLookupRepo.DataSourceConnect("Name", "Name", Countries)
CountryCodeLookUp.DataSourceConnect("ISO2", "ISO2", Countries)
How can I link them up so that ISO2 will be filled automatically after Name is selected?
Thanks
Figured out how to do it.
In case someone else is wondering, this is how I did it :
Dim Country As clCountry = CountriesLookupRepo.GetDataSourceRowByKeyValue(e.Value)
Apt.CountryCode = Country.ISO2
Apt.RegionName = Country.Region
I suggest you to go through this DevExpress thread which describes most of cases to implement this functionality.
How to filter a second LookUp column based on a first LookUp column's value
GridControl, TreeList, and VGridControl provide a special event that
is raised when a cell editor is activated: ShownEditor. This is the
best moment to replace the LookUp editor's data source with the
collection filtered by an appropriate criterion.
example:
Private Sub gridView1_ShownEditor(ByVal sender As Object, ByVal e As EventArgs)
Dim view As ColumnView = DirectCast(sender, ColumnView)
If view.FocusedColumn.FieldName = "CityCode" AndAlso TypeOf view.ActiveEditor Is LookUpEdit Then
Dim edit As LookUpEdit = CType(view.ActiveEditor, LookUpEdit)
Dim countryCode As String = CStr(view.GetFocusedRowCellValue("CountryCode"))
edit.Properties.DataSource = GetFilteredCities(countryCode)
End If
End Sub
and for more information related to your quest of binding XPO objects with LookupEdit check this KB example:
How to: Bind an XPCollection to a LookUp
example:
XPCollection xpCollectionPerson = new XPCollection(typeof(Person));
xpCollectionPerson.DisplayableProperties = "Name;Group!Key";
gridControl1.DataSource = xpCollectionPerson;
XPCollection xpCollectionGroup = new XPCollection(typeof(PersonGroup));
RepositoryItemLookUpEdit lookUpRI = new RepositoryItemLookUpEdit();
lookUpRI.DataSource = xpCollectionGroup;
lookUpRI.DisplayMember = "GroupName";
lookUpRI.ValueMember = "Oid";
gridControl1.RepositoryItems.Add(lookUpRI);
// Associate the LookUpEdit editor with the "Group!Key" column.
(gridControl1.MainView as ColumnView).Columns["Group!Key"].ColumnEdit = lookUpRI;
Hope this help.
I am not sure if the title is misleading but I wasn't sure how to summarise this one.
I have a table in an SQL DB where a record exists as below:
I would like to display the measurement values of this item in a gridview as below:
I thought about selecting the target values to a list (and the same for the actual values) as below:
Dim cdc As New InternalCalibrationDataContext
Dim allTargetvalues = (From i In cdc.int_calibration_records
Where i.calibration_no = Request.QueryString(0) And
i.calibration_date = Request.QueryString(1)
Select i.measure1_target, i.measure2_target, i.measure3_target).ToList()
Then joining the lists together in some way although I am unsure of how I could join the lists or even if this is the correct approach to be taking?
Well, let me first say that measure1_target, measure2_target, etc. is almost always indicative of bad database design. These should probably be in another table as the "many" end of a 1-to-many relationship with the table you posted. So to answer one of your questions: No, this is not the correct approach to be taking.
With the structure of your table in its current state, your best option is probably something like this:
Dim cdc As New InternalCalibrationDataContext
Dim allTargetValues As New List(Of Whatever)
For Each targetValue In (From i In cdc.int_calibration_records
Where i.calibration_no = Request.QueryString(0) AndAlso
i.calibration_date = Request.QueryString(1)
Select i)
allTargetValues.Add(New Whatever With {.MeasureNumber = 1,
.Target = targetValue.measure1_target,
.Actual = targetValue.measure1_actual })
allTargetValues.Add(New Whatever With {.MeasureNumber = 2,
.Target = targetValue.measure2_target,
.Actual = targetValue.measure2_actual })
allTargetValues.Add(New Whatever With {.MeasureNumber = 3,
.Target = targetValue.measure3_target,
.Actual = targetValue.measure3_actual })
Next
The Whatever class would look like this:
Public Class Whatever
Public Property MeasureNumber As Integer
Public Property Target As Integer
Public Property Actual As Integer
End Class
Okay so here is what I have:
Do
x = x + 1
Dim myTxt As New TextBox
myTxt.Name = ("TbMat" & x.ToString())
myTxt.Location = New Point(13, 13 + (x * 37))
myTxt.Tag = "For DB"
myTxt.Visible = True
Button2.Location = New Point(13, 39 + (x * 37))
If x = 5 Then
Button1.Dispose()
End If
Me.Controls.Add(myTxt)
Me.Refresh()
Loop Until x >= 1
It's my makeshift way of letting the user add a textbox by clicking a button. I am new to programming so this may be an easy fix but here is my question... when the user adds a textbox I want the first one to be "TbMat1" so I would assume to call upon it to get information I would just use, for example, textbox1.text=TbMat1.text. When I do this, it says TbMat1 is not declared, which is obvious since it isn't created yet.
I need help pulling information from the new textboxes to other textboxes, and later I will figure out exporting. Thanks.
When you created the control, you created it as myTxt which is its object reference. So in the procedure where that code block exists this would work:
SomeOtherTB.Text = myTxt.Text
The name is just the name, not an object reference or 'handle'. Further, once the code exits that procedure myTxt goes out of scope because that is where it was declared (Dim or Private|Friend|Public). To access your new control elsewhere:
SomeOtherTB.Text = Me.Controls("TbMat1") ' or "TbMat" & x.ToString()
OR create a new object ref if you want:
Friend myTB AS TextBox ' module level at least
myTb = Me.Controls("TbMat1")
The latter might not be practical if you are making lots of them.