i want to make a variable can be used in .caption, so i can get the value and used it to make something.
last experiment, i use it in foxpro and it can work pretty well.
like this.
foxpro code mix variable with system
tmbl = "command"+alltrim(str(i)) set order to no_room seek
(thisform.pageframe1.page1.&tmbl..caption
see the &tmbl.?? im using it as a connector to .caption
now im trying to do it in VB.NET. it can not work. i don't know what kind connector must be use in VB.NET. so can somebody please tell what must to use in VB.NET?
You can simply use controls collection to find the control you want (and even in VFP it is the way to go, instead of abusing the & operator). Say you want to do this for a label, in C# it looks like:
var label = this.Controls.OfType<Label>()
.SingleOrDefault(c => c.Name == "command" + i);
if (label != null)
{
label.Text = "Whatever";
}
Telerik code converter converts this to VB.Net as:
Dim label = Me.Controls.OfType(Of Label)().SingleOrDefault(Function(c) c.Name = "command" + i)
If label IsNot Nothing Then
label.Text = "Whatever"
End If
Related
I know that when adding text/content/DataContext in XAML you refer to resource dictionary or inline mark up for styling around text or in template.
Q:
However I'm having trouble trying to find a way to do the following:
Data is coming from a View Model/Model that is pulled from a database.
(string value)
I am a <Bold>smart</Bold> man.
to show in a flow document like this:
I am a smart man.
Q end
Either by binding to a converter, behavior, or would saving the paragraph/document that I put in the flow document to a .rtf file in memory stream be a better option?
I've tried to utilize the option for behavior listed > here < but that is for text block and unable to redirect for type text instead of text block.
Trying to make it streamlined.
Tried to use data binding and apply the converter but even though I have the resource for the behavior / converter, it work due to the type conversion.
One clever solution is presented by Rockford Lhotka in post Set rich text into RichTextBlock control. His idea is to create a custom control which then creates the RichTextBlock using XamlReader.Load.
This allows you to use code like the following:
<local:RichTextDisplay Xaml="{Binding Hello}" HorizontalAlignment="Center"
VerticalAlignment="Center"/>
Where Hello is:
public string Hello { get; set; } = "I am a <Bold>smart</Bold> man.";
With a result:
If you use UWP/Win 8.1 XAML, you can use the original code from the blog post with the following small change (Paragraphs added):
<UserControl
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:mc=""http://schemas.openxmlformats.org/markup-compatibility/2006"">
<Grid>
<RichTextBlock><Paragraph>");
xaml.Append(ctl.Xaml);
xaml.Append(#"
</Paragraph></RichTextBlock>
</Grid>
</UserControl>
");
To answer my own question:
My case was creating a Document style display for user to update and save as a PDF, but I didn't want to rely on Office being on our application Server.
So I resolved this in my case by using a full "doc.RTF" document and importing that as a memory stream/string and apply my needed updates for values to that.
i.e. VB.net snippet example
Using uStream = Assembly.GetExecutingAssembly.GetManifestResourceStream("Resourcefilepath.rtf")
Using mStream As system.IO.MemoeryStream = New MemoryStream()
uStream.CopyTo(mStream)
rtfstring = Encoding.UTF8.GetSTring(mStream.toArray())
'--Do the updates to the needed string as needed:
rtfstring.Replace("Value","UpdatedValue")
'--Load Property Memory String this method is returnind
RTFDataProperty = New MemoryStream(Encoding.UTF8.GetBytes(rtfstring))
End Using
End Using
Then I loaded my XAML Rich Text Box with that memory stream as DataFormats.Rtf.
RichTextBox1.SelectAll()
RichTextBox1.Selection.Load(ClassName.RTFDataProperty, DataFormats.Rtf)
This gave me a template for formatting and layout of that document. (More of a case scenario and not a normal practice)
I also wanted to apply a starting selection so here is what I did there:
'--Get my RichTextBox Text
rtbtext As String = New TextRange(RichTextBox1.Document.contentStart, RichTextbox1.Document.ContentEnd).Text
Dim strStartSelection As String = "Comments..."
Dim startTP As TextPointer
Dim endTP As TextPointer
'--Loop through the paragraphs of the richtextbox for my needed selection starting point:
For Each para As Paragraph In RichTextBox1.Document.Blocks
Dim paraText As String = New TextRange(para.ContentStart, para.ContentEnd).Text
If paraText = "" Then
Dim pos As TextPointer = para.ContentStart
startTP = pos
endTP = startTP.GetPositionAtOffset("".Length + 3) '--my string had ... on the end so had to add for avoiding the escape of that on length
RichTextBox1.Selection.Select(startTP, endTP)
RichTextBox1.Focus()
Exit For
End If
Next
This is the simple VB.net code layout, but you can simplify and adjust from there if you find it useful.
Thanks
I'm trying to format a Ultragridcell using the following code and it works fine.
//Code
DefaultEditorOwnerSettings editorSettings;
DateTimeEditor datetime_editor;
editorSettings = new DefaultEditorOwnerSettings()
editorSettings.DataType = typeof(DateTime);
editorSettings.MaskInput = "mm/dd/yyyy";
datetime_editor = new DateTimeEditor(new DefaultEditorOwner(editorSettings));
e.Row.Cells["DateInfo"].Editor = datetime_editor;
But when I try to format like the below code, it fails.
//Code
DefaultEditorOwnerSettings editorSettings;
DateTimeEditor datetime_editor;
editorSettings = new DefaultEditorOwnerSettings()
editorSettings.DataType = typeof(DateTime);
editorSettings.MaskInput = "D";
datetime_editor = new DateTimeEditor(new DefaultEditorOwner(editorSettings));
e.Row.Cells["DateInfo"].Editor = datetime_editor;
Is that only the custom formatting that too only limited types works with the cell or i'm wrong somewhere.
Need an advice on this.
It seems that you think that MaskInput property supports all the formatting functionality provided by Composite Formatting, but I don't think that it is true.
The formatting available for MaskInput as far as I know are limited to only these provided by the UltraGrid Designer.
Using the UltraGrid Designer (right click on the UltraGrid control, select UltraGrid Designer) click on the Data Schema and define a data schema in which one of the columns will be a DateTime column. Then go to the Bands and Column Settings node, select columns and then the column defined as DateTime. In the properties window you can find the MaskInput property and its allowed values. You could try to experiment with the predefined masks and check if there is one that fits your requirements.
As I have said this is what I suppose to be true. I don't know if there is another advanced mode to set these properties at design time or at Runtime. If, someone from Infragistics, wants to add something to this answer would be welcome
Im writting an Application for Win8 with C# and Xaml.
I have an Control with an Control-Template, i can add Components statically to the Control-Template.
But when i add Them in the Code Behind like this:
TextBlock Text = new TextBlock();
Text.Name = "Text" + rand.Next(999999);
Text.Text = info.Name;
The Textblock is not shown when i add the Control to an Page.
You need to add the newly created controls to the hosting control. e.g., if you have a stackpanel you can add the textbox to it with something like
TextBlock Text = new TextBlock();
Text.Name = "Text" + rand.Next(999999);
Text.Text = info.Name;
myStackPanel.Children.Add(Text);
note : untested, but I'm pretty sure the syntax is right
I'm trying to use two devExpress checkedComboBoxes (boxes) to maintain a list and its antilist (i.e, same items in both comboboxes, and they must be checked in only one of the lists).
I'm using C++/CLI, so for each box I handle
EditValueChanged += gcnew System::EventHandler(this, &SelectionControl::exclBox_EditValueChanged);
which calls through to
void
box_ToggleAntibox(
DevExpress::XtraEditors::CheckedComboBoxEdit^ box,
DevExpress::XtraEditors::CheckedComboBoxEdit^ antibox )
{
using namespace DevExpress::XtraEditors::Controls ;
cli::array<String ^> ^ sAnti = gcnew cli::array<String ^>(2*box->Properties->Items->Count) ;
int ii = 0;
String ^ delim = ", ";
for each (CheckedListBoxItem^ i in box->Properties->GetItems()) {
if (i->CheckState==Windows::Forms::CheckState::Unchecked)
{
sAnti[ii] = i->Value->ToString();
++ii;
sAnti[ii] = delim;
++ii;
}
}
String ^ result = String::Concat(sAnti);
antibox->EditValue = result;
}
As the devExpress documentation seems to say to set the edit value, rather than simply iterating through the box list and setting the anti-list to !Checked.
However, it doesn't seem to be working (the correct items are added to the text window, but nothing is checked). Moreover, if I look at my box after the event has finished, I find that the string value in the text window is correct (reflects what I'd selected), but if I open it up, then all items are selected.
Does anyone have any suggestions I might try?
Is it better to set each item's CheckState::Checked instead?
Thanks!
I spent some time talking to DevExpress support. The short answer is that this should work - but doesn't for us. Your mileage may vary, but our solution was to put the two comboboxes on to separate controls on the form.
i am creating a table in vb.net code (htmltable) with htmltablerows and htmltablecell. I gave on image control but thatr control cant have the .imageurl property, which i need cause i have a handler image.ashx which brings image from the database.
heres' the code -
TD = New HtmlTableCell
Dim img As New HtmlImage()
img.ID = "image_" & rd("ID")
img.Style.Add("width", "100px")
img.Style.Add("height", "100px")
img.ImageUrl = "Image.ashx?id=" & rd("ID")
on the last line, "img.ImageUrl" i get this error -
'ImageUrl' is not a member of 'System.Web.UI.HtmlControls.HtmlImage'
how do i fix this?
ImageUrl is a member of the System.UI.WebControls.Image control. By contrast, you are using the direct HtmlImage control which is rendered exactly as an img tag would be. You should use the Src property of the HtmlImage control instead.