aspx.cs
string aa= dt.Rows[0]["fruit"].ToString();
if (aa== "apple")
{
RadioApple.Checked = true;
RadioLemon.Checked = false;
}
else
{
RadioLemon.Checked = true;
RadioApple.Checked = false;
}
I would like to make it in short way like this:
string aa= dt.Rows[0]["fruit"].ToString();
RadioButton rb= RadioGroupFruit.Items.Find(aa);
rb.Checked = true;
Any ideas?
using ext.net in asp.net
For RadioButtonGroups & CheckBoxGroups try getting the value of the BoxLabel.
// pseudo code
string[] selectedFruit = this.CheckboxGroupFruity.items.where(q => q.Checked).select(q => q.BoxLabel).ToArray();
Related
I have application where i am trying to make checkbox checked based on value i get from string. String name is called aktivan and returns values Da or Ne, i checked with messagebox and values are here and valid. If value are Da it need to check checkbox but it doesn't work.
chkAktivan.Checked = aktivan == "Da" ? true : false; // doesn't work
chkAktivan.Checked = true; // working
chkAktivan.Checked = false; // working
Same is for radio, based on string values Muški or Ženski it need to set values but also does't working all time its checking Ženski radio.
if (spol == "Muški")
{
radioMuski.Checked = true;
radioZenski.Checked = false;
}
else
{
radioMuski.Checked = false;
radioZenski.Checked = true;
}
You should trim the values before using them, like this.
if (spol.Trim() == "Muški")
{
radioMuski.Checked = true;
radioZenski.Checked = false;
}
else
{
radioMuski.Checked = false;
radioZenski.Checked = true;
}
And also this.
chkAktivan.Checked = aktivan == "Da" ? true : false;
To this:
chkAktivan.Checked = aktivan.Trim() == "Da" ? true : false;
partial answer
For the first part of your question, regarding this line:
chkAktivan.Checked = aktivan == "Da" ? true : false;
Try changing it to:
chkAktivan.Checked = (aktivan == "Da" ? true : false);
OR MORE SIMPLY:
chkAktivan.Checked = "Da".Equals(aktivan);
According to this post, you can make Visual Studio find.
I update the code of Asif Iqbal K from the article a bit to eliminate build error.
public const string vsWindowKindFindResults1 = "{0F887920-C2B6-11D2-9375-0080C747D9A0}";
public string FindInFiles(string searchText)
{
EnvDTE80.DTE2 dte;
dte = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");
dte.MainWindow.Activate();
EnvDTE.Find find = dte.Find;
find.Action = EnvDTE.vsFindAction.vsFindActionFindAll;
find.FindWhat = searchText;
find.MatchWholeWord = false;
find.ResultsLocation = EnvDTE.vsFindResultsLocation.vsFindResults1;
find.Target = EnvDTE.vsFindTarget.vsFindTargetSolution;
find.PatternSyntax = EnvDTE.vsFindPatternSyntax.vsFindPatternSyntaxRegExpr;
find.SearchSubfolders = true;
var x = dte.Find.FindWhat;
EnvDTE.vsFindResult result = find.Execute();
var findWindow = dte.Windows.Item(vsWindowKindFindResults1);
string data = "";
System.Threading.Thread.Sleep(5000);//Comment out this code to see the problem, this line of code is not the solution though.
if (result == EnvDTE.vsFindResult.vsFindResultFound)
{
var selection = findWindow.Selection as EnvDTE.TextSelection;
selection.SelectAll();
data = selection.Text;
}
return data;
}
I see that the problem is the function return the string (string data) too early, so it can't get all the text from the result window.
So the code comes so close to get the find text. One remaining puzzle is to check if the find process complete, then get the text.
So the question is: replace what code with the code
System.Threading.Thread.Sleep(5000);
So that the function FindInFiles() can get all the text of 'FindResult 1" window.
Thanks for reading.
Here is the solution
EnvDTE80.DTE2 s_dte;
EnvDTE.FindEvents s_findEvents;
public const string vsWindowKindFindResults1 = "{0F887920-C2B6-11D2-9375-0080C747D9A0}";
public frmFindHelper()
{
InitializeComponent();
s_dte = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");
s_dte.MainWindow.Activate();
s_findEvents = s_dte.Events.FindEvents;
s_findEvents.FindDone += new EnvDTE._dispFindEvents_FindDoneEventHandler(OnFindDone);
}
private void OnFindDone(EnvDTE.vsFindResult result, bool cancelled)
{
if (result == EnvDTE.vsFindResult.vsFindResultFound)
{
var findWindow = s_dte.Windows.Item(vsWindowKindFindResults1);
string data = "";
var selection = findWindow.Selection as EnvDTE.TextSelection;
selection.SelectAll();
data = selection.Text;
MessageBox.Show("Done!");
}
}
private void btnFind_Click(object sender, EventArgs e)
{
EnvDTE.Find find = s_dte.Find;
find.Action = EnvDTE.vsFindAction.vsFindActionFindAll;
find.FindWhat = txtSearch.Text;
find.MatchWholeWord = false;
find.ResultsLocation = EnvDTE.vsFindResultsLocation.vsFindResults1;
find.Target = EnvDTE.vsFindTarget.vsFindTargetSolution;
find.PatternSyntax = EnvDTE.vsFindPatternSyntax.vsFindPatternSyntaxRegExpr;
find.SearchSubfolders = true;
var x = s_dte.Find.FindWhat;
EnvDTE.vsFindResult result = find.Execute();
}
Thanks to Ed Dore from this post
I have a popupcontrol declared in my razor cshtml file as follow:
#Html.DevExpress().PopupControl(settings =>
{
settings.Name = "popSendBackReview";
settings.HeaderText = "Send Review Back to Scheduler";
settings.AllowResize = false;
settings.ShowHeader = true;
settings.ShowOnPageLoad = false;
settings.AllowDragging = true;
settings.CloseAction = CloseAction.CloseButton;
settings.CloseOnEscape = false;
settings.Modal = true;
settings.PopupElementID = "popSendBackReview";
settings.AutoUpdatePosition = true;
settings.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter;
settings.PopupVerticalAlign = PopupVerticalAlign.WindowCenter;
settings.Height = 280;
settings.Width = 450;
settings.SetContent(() =>
{
Html.RenderPartial("_SendBackReviewPanel");
});
}).GetHtml()
The partial view contains a memo box and button that calls an action:
#Html.DevExpress().Memo(settings =>
{
settings.Width = 300;
settings.Height = 150;
settings.Style.Add("margin-bottom", "10px");
settings.Name = "txtReviewComment";
settings.Properties.ValidationSettings.RequiredField.IsRequired = true;
settings.Properties.ValidationSettings.RequiredField.ErrorText = "A Review Comment is Required.";
settings.Properties.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.Text;
settings.Properties.ValidationSettings.ErrorTextPosition = ErrorTextPosition.Bottom;
settings.Properties.ValidationSettings.Display = Display.Dynamic;
settings.Properties.ValidationSettings.ValidationGroup = "Review";
}).GetHtml()
#Html.DevExpress().Button(settings =>
{
settings.Name = "btnSaveReview";
settings.Text = "Send Back for Scheduler Review";
settings.UseSubmitBehavior = false;
settings.ValidationGroup = "Review";
settings.RouteValues = new { Controller = "Matter", Action = "ResolveReview", Pass = false, Comment = Model.CommentText };
}).GetHtml()
#Html.DevExpress().Button(settings =>
{
settings.Name = "btnCancelReview";
settings.Text = "Cancel";
settings.UseSubmitBehavior = false;
settings.ClientSideEvents.Click = "function(s,e) { popSendBackReview.Hide(); }";
}).GetHtml()
I am trying to get the text that is typed into this box on the server side (in the action on my controller). In other places in my application I have been able to use the following code to get values of controls:
public ActionResult ResolveReview(bool Pass)
{ ...
EditorExtension.GetValue<string>("txtReviewComment")
...}
However this returns null in this scenario. What is the correct way to get this value from a control in a partial view rendered in a popupcontrol?
In general, it is necessary to wrap editors within a form container in order to pass the entire form's content on submit. Then, it is possible to retrive the required editor's value using the standard Model Binding mechanism. When using DevExpress MVC Editors, make sure that the DevExpressEditorsBinder is registered:
#using(Html.BeginForm("ResolveReview")) {
#Html.DevExpress().Memo(settings => {
settings.Name = "txtReviewComment";
}).GetHtml()
#Html.DevExpress().Button(settings => {
settings.Name = "btnSaveReview";
settings.UseSubmitBehavior = true;
}).GetHtml()
}
public ActionResult ResolveReview(bool Pass) {
EditorExtension.GetValue<string>("txtReviewComment")
}
or
public ActionResult ResolveReview(string txtReviewComment) { ... }
Check the MVC Data Editors - Model Binding and Editing learning resource.
I found the answer on my own, my button was causing a GET method to fire instead of POST. By setting "UseSubmitBehavior" to true on my save button, it started firing the POST function and allowing the
EditorExtension.GetValue<string>("txtReviewComment")
line to get a value.
How to go add content control in specific start and end range of footnote? I can add content control in document.range, but I am unable to add in footnote, please help to do this. If anyone reply quickly, I will be proved of you.
public void FindItalicFootnote(String FindText)
{
foreach (Word.Footnote footNote in Word.Document.Footnotes)
{
Word.Range RngFind = footNote.Range;
RngFind.Find.Forward = true;
if (RngFind.Find.Execute(FindText))
{
while (RngFind.Find.Found)
{
RngFind.Select();
object strtRange = Word.Selection.Range.Start;
object endRange = Word.Selection.Range.End;
string placeHolder = "";
bool findCase = false;
if (Word.Selection.Range.ParentContentControl == null && Word.Selection.Range.ContentControls.Count == 0)
{
RngFind.Select();
while (Word.Selection.Previous(Unit: Word.WdUnits.wdWord, Count: 1).Font.Italic == -1)
{
Word.Selection.Previous(Unit: Word.WdUnits.wdWord, Count: 1).Select();
strtRange = Word.Selection.Range.Start;
placeHolder = "{VerifiedBy='Italic'}";
findCase = true;
}
Word.ContentControl CC = RngFind.ContentControls.Add(Word.WdContentControlType.wdContentControlRichText,
footNote.range(strtRange, endRange));
//my query is, how to say footNote.range(start, end), in main part I wrote as Word.Document.range(startRange, endRange)
CC.Title = "Case Reference";
CC.Tag = Guid.NewGuid().ToString();
CC.SetPlaceholderText(Text: placeHolder);
}
RngFind.Find.Execute(FindText);
}
}
}
}
Regards,
Saran
I have two groups of radio buttons (2 groups of 4 buttons), which I would like to save the checked status of and load the checked status as soon as the program/main form loads up. The radio buttons are NOT on the main form.
How can I do this using Properties.Settings?
The code on the "Preference" form is as follows:
public string DataFormat, KeyboardFormat;
public void UpdateUserChoice(string date, string keyboard)
{
if (date == ddmmyyyy.Text)
ddmmyyyy.Checked = true;
else if (date == mmddyyyy.Text)
mmddyyyy.Checked = true;
else if (date == yyyyddmm.Text)
yyyyddmm.Checked = true;
else if (date == yyyymmdd.Text)
yyyymmdd.Checked = true;
//----------------------------------------------------------
if (keyboard == qwerty.Text)
qwerty.Checked = true;
else if (keyboard == qwertz.Text)
qwertz.Checked = true;
else if (keyboard == azerty.Text)
azerty.Checked = true;
else if (keyboard == dvorak.Text)
dvorak.Checked = true;
}
private void button1_Click(object sender, EventArgs e)
{
if (ddmmyyyy.Checked)
DataFormat = ddmmyyyy.Text;
else if (mmddyyyy.Checked)
DataFormat = mmddyyyy.Text;
else if (yyyyddmm.Checked)
DataFormat = yyyyddmm.Text;
else if (yyyymmdd.Checked)
DataFormat = yyyymmdd.Text;
//--------------------------------------------------
if (qwerty.Checked)
KeyboardFormat = qwerty.Text;
else if (qwertz.Checked)
KeyboardFormat = qwertz.Text;
else if (azerty.Checked)
KeyboardFormat = azerty.Text;
else if (dvorak.Checked)
KeyboardFormat = dvorak.Text;
this.Close();
}
And the code on the MainForm is:
private void DateStamp()
{
if (dateFormat.ToUpper() == "DD/MM/YYYY")
{
int CaretPosition = richTextBoxPrintCtrl1.SelectionStart;
string TextBefore = richTextBoxPrintCtrl1.Text.Substring(0, CaretPosition);
string textAfter = richTextBoxPrintCtrl1.Text.Substring(CaretPosition);
string currentDate = DateTime.Now.ToString("dd-MM-yyyy");
richTextBoxPrintCtrl1.SelectedText = currentDate;
}
else if (dateFormat.ToUpper() == "MM/DD/YYYY")
{
int CaretPosition = richTextBoxPrintCtrl1.SelectionStart;
string TextBefore = richTextBoxPrintCtrl1.Text.Substring(0, CaretPosition);
string textAfter = richTextBoxPrintCtrl1.Text.Substring(CaretPosition);
string currentDate = DateTime.Now.ToString("MM-dd-yyyy");
richTextBoxPrintCtrl1.SelectedText = currentDate;
}
else if (dateFormat.ToUpper() == "YYYY/DD/MM")
{
int CaretPosition = richTextBoxPrintCtrl1.SelectionStart;
string TextBefore = richTextBoxPrintCtrl1.Text.Substring(0, CaretPosition);
string textAfter = richTextBoxPrintCtrl1.Text.Substring(CaretPosition);
string currentDate = DateTime.Now.ToString("yyyy-dd-MM");
richTextBoxPrintCtrl1.SelectedText = currentDate;
}
else if (dateFormat.ToUpper() == "YYYY/MM/DD")
{
int CaretPosition = richTextBoxPrintCtrl1.SelectionStart;
string TextBefore = richTextBoxPrintCtrl1.Text.Substring(0, CaretPosition);
string textAfter = richTextBoxPrintCtrl1.Text.Substring(CaretPosition);
string currentDate = DateTime.Now.ToString("yyyy-MM-dd");
richTextBoxPrintCtrl1.SelectedText = currentDate;
private void preferencesToolStripMenuItem_Click(object sender, EventArgs e)
{
UserPreferences pref = new UserPreferences();
pref.UpdateUserChoice(dateFormat, keyboardFormat);
pref.ShowDialog();
dateFormat = pref.DataFormat;
keyboardFormat = pref.KeyboardFormat;
}
private void virtualKeyboardToolStripMenuItem1_Click(object sender, EventArgs e)
{
if (keyboardFormat.ToUpper() == "QWERTY")
{
Virtual_Keyboard vKeyboard = new Virtual_Keyboard();
vKeyboard.Show();
}
else if (keyboardFormat.ToUpper() == "QWERTZ")
{
QWERTZ qwertz = new QWERTZ();
qwertz.Show();
}
else if (keyboardFormat.ToUpper() == "AZERTY")
{
AZERTY azerty = new AZERTY();
azerty.Show();
}
else if (keyboardFormat.ToUpper() == "DVORAK")
{
DVORAK dvorak = new DVORAK();
dvorak.Show();
}
}
I would like to save the checked status of the radio buttons (as seen in the picture attached), so that when the user reopens the program, these "settings" are also loaded. How would I achieve this? Using Properties.Settings if it's possible.
I've created two "Settings". DatePreference and KeyboardPreference. I don't know what "type" they should be, either. If somebody could guide me, I'd really appreciate it. I'm new to programming so thank you for your help.
The RadioButtons are named:
ddmmyyyy
mmddyyyy
yyyyddmm
yyyymmdd
qwerty
qwertz
azerty
dvorak
Thanks for your help.
--EDIT--
I forgot to mention that this is a WinForms application.
Example for the date (you can do the same for keyboard) :
Maybe you can create an enum like this :
public enum DatePreference { dd_mm_yyyy, mm_dd_yyyy, yyyy_dd_mm, yyyy_mm_dd };
Set in the Settings DatePreference as Integer
For your Preference form code :
UpdateUserChoice :
if (Properties.Settings.Default.DatePreference == (int)DatePreference.dd_mm_yyyy)
ddmmyyyy.Checked = true;
button1_Click :
if (ddmmyyyy.Checked)
{
DataFormat = ddmmyyyy.Text;
Properties.Settings.Default.DatePreference = (int)DatePreference.dd_mm_yyyy;
}
Think to save the changes with Properties.Settings.Default.Save(); !
For your Main form code :
if (Properties.Settings.Default.DatePreference == (int)DatePreference.dd_mm_yyyy)
{
int CaretPosition = richTextBoxPrintCtrl1.SelectionStart;
string TextBefore = richTextBoxPrintCtrl1.Text.Substring(0, CaretPosition);
string textAfter = richTextBoxPrintCtrl1.Text.Substring(CaretPosition);
string currentDate = DateTime.Now.ToString("dd-MM-yyyy");
richTextBoxPrintCtrl1.SelectedText = currentDate;
}
[...]
I would represent the values in an enum.
public enum AvailableKeyboardLayouts
{
DVORAK = 0,
QWERTY = 1,
QWERTZ = 2
}
Using the Settings file you can save the type as string or int. Use Enum.Parse to transform the object
Saving and loading from the Settings files are easy:
My settings file is Settings.settings
Settings.Default.KeyboardPreference = AvailableKeyboardLayouts.DVORAK;
Settings.Default.Save();
How about using the Resources.resx file (depends on the project)
Also you can use an xml file to save the values. If you have many settings then you can use a Datatable (named for example "Settings") , place it inside a Dataset and use SaveToXml and LoadFromXml for faster results.