C# Yes No box with variable overload? - overloading

I'm building a word search application for my term 1 University project, I basically have a Windows Form Application which uses an array to populate a list box when a user inputs text into the "Add" field. I also have included the option to remove added items to the list but wanted to create a question box to ask the user if they wanted to delete item {0} in the array.
I have been experimenting for a good hour or so and could not find anything on the net to solve my problem. Below is my code snippet to the applicable section...
//Clear the contents of the selected item
private void deleteBtn_Click(object sender, EventArgs e)
{
string findMyWord = findLst.Text;
if (MessageBox.Show(string.Format("You are trying to clear the contents of {0}, do you wish to proceed?", findMyWord, "Delete the items contents?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) == DialogResult.Yes)
{
findLst.Items.Remove(findLst.SelectedItem);
}
Thanks in advance.

Related

Regex Validation for TreelistEx is not working

In Sitecore Content editor/Page editor, when I add items to TreelistEx I would like the TreelistEx to allow only 12 items. To achieve this solution, I have added a Regex ^.{0,467}$ in the validation field inside the template section in which I want to limit the items.
I have referred this article
This Regex works properly in Content editor. But for the page editor whenever I add an items in treelistEx it works fine for the first time but again if I add/remove items it gives me validation message for both greater and less number of items just after on click of "Ok"and items are also not saved.
Ideally it should give validation message if number of items are greater than 12 and only on Click of "save" button same as it is working in Content editor. How can I solve this Regex validation problem in Page editor? I am using Sitecore 8.1
I also had the same issue a while ago and because of the limited time i had i implemented a not so ideal way but you can implement it if you want.
Let the user add the items and then just grab the first 12 in your code. It will be something like this:
Create a method to get the multicast item (For flexibility).
public static MultilistField GetMultilistField(Item item, string fieldName)
{
if (item != null && !string.IsNullOrWhiteSpace(fieldName))
{
MultilistField field = item.Fields[fieldName];
if (field != null)
{
return field;
}
}
return null;
}
Get the items within the Miltilist field.
MultilistField field = GetMultilistField[DatasourceItem, "fieldName"];
var returnList = field.GetItems().Where(c => c.TemplateName.Equals("someValidationIfYouWant")).ToList().Take(12);

Sitecore get all parent (ancestor) with little processing (performance)

I'm trying to come up with solution on getting all the ancestors for the context item. One option is to store _path in index and other option is to do similar to one below:
http://www.glass.lu/Blog/GettingAncestors
I'm having no luck with getting the solution work for above (glass mapper) solution.
I got the index solution working but would like to avoid using index just to get the _path (collection of ancestors) as we don't have any other requirements to use index e.g. search etc.
Appreciate if someone could share the snippet for working solution or even better if Glassmapper has already included the above blog solution.
The most efficient way to check if one item is a descendant of another is to simply check that the current item property Paths.LongID starts with the LongID of the parent item:
Item currentItem = Sitecore.Context.Item;
IList<Item> menuItems = GetMenuItems();
foreach (var menuItem in menuItems)
{
bool isActive = currentItem.Paths.LongID.StartsWith(menuItem.Paths.LongID);
// do code
}
This will work since the path GUIDs are unique for each item.
Alternatively, if you want to use Glass models only then you can use the SitecoreInfoType.FullPath attribute:
[SitecoreInfo(SitecoreInfoType.FullPath)]
public virtual string FullPath { get; private set; }
And then from your code you can simply check:
Item currentItem = Sitecore.Context.Item; //or use SitecoreContext() to get a strongly types model
IEnumerable<MenuItem> menuItems = GetMenuItems();
foreach (var menuItem in menuItems)
{
bool isActive = currentItem.Paths.FullPath.StartsWith(menuItem.FullPath);
// do code
}
Just a word of warning, since each menu item now need code to run in order to determine state, this will make your menu component difficult to cache, resulting caching too many variations or caching per page. You would be better to move this logic into Javascript to set the menu state using the current page URL, this will allow your component to be cached once for all pages.

Qt: Linking my model data with a QListView

I'm writing my first Qt project (so I'm new to the environment) and I've got this project build using the MVC design pattern.
It's a pretty basic note manager/editor. I've got a class uiman ("Ui Manager") which takes care of my UI, and my function to open a notes database (which is just a list of text files to open)
void uiman::openDBDialog(){
QFileDialog dialog;
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setDirectory("/Users/myuserdir/Desktop");
dialog.setFilter(QDir::Files);
dialog.setWindowTitle("Open File");
dialog.setNameFilter("Textie Notes DB(*.db)");
dialog.exec();
QString pathDB = dialog.selectedFiles().first();
model = new notesModel();
model->setNotesDB(new QString(pathDB.toUtf8().constData()));
refreshAll();
}
so far, so good. I take the path of my database and give it to my model, which should now manage the rest.
Now, the refreshAll() function should take the list I opened up and show them in my QListView, but I can't parse the file and append items on the go using clear() and append() unlike the QListWidget. So, how do I approach building a vector (I suppose) of names from my file and feeding them to my QListView?
Sorry if I'm not being clear, but the official documentation hasn't been clear enough.
Edit: This is my model, nodesmodel, and here's the code.
notesModel::notesModel(QObject *parent) :
QFileSystemModel(parent)
{
QStringList noteList;
}
void notesModel::setNotesDB(QString *dbpath){
// open the notes database
databasepath = dbpath;
}
QFile* notesModel::getDB(){
if(this->dbFile == NULL)
this->dbFile = new QFile(databasepath- >toUtf8().constData());
return this->dbFile;
}
As you already noticed, you do not add/remove data from the viewer widget itself, this is done in the model.
You can set the model with the setModel() method.
If you want to show a simple QString list, then you can use:
QStringList strings;
strings << "String 1" << "String 2" << "String 3";
model = new QStringListModel(strings, parent);
view->setModel(model);
// model is managed by parent, and will be deleted when parent is deleted.
// If you create multiple models you might consider other memory management strategy
To read a text file and store its lines in a QStringList, see this answer.

How to highlight the selected item of long list selector in windows phone 8

I've developed Windows Phone 8 application. In that I'm using the Long list selector to display items in the list. Everything is fine up till now. When the user clicks on any item of long list selector, I want to highlight that item's background color, so that the user clearly understands that he/she has selected an item.
Could you please tell me how to do this in windows phone 8.
I'm looking forward for the response.
http://code.msdn.microsoft.com/wpapps/Highlight-a-selected-item-30ced444
Detailed example of how to do it
I like to have more control of my application through code and avoid doing things in the xaml where it can get complicated. Below is a simpler way I feel and gives more control in code and require minimal changes in the xaml. It keeps the xaml nice and clean for what should be a really simple action.
Add a "BackColor" (or other string) property to your bound object
public string BackColor { get; set; }
Bind that property to something in your xaml like the background or a stack panel or the border color of a border, something that will present the visual change. E.g.
<StackPanel Orientation="Horizontal" Background="{Binding BackColor}">
In your long list selector code "SelectionChanged" event update the bound objects using the AddedItems and RemovedItems collections from SelectionChangedEventArgs e
if (e.AddedItems.Count > 0)
{
if (e.AddedItems[0] != null)
{
oMyObject = (MyServices.MyObjectDao)e.AddedItems[0];
oMyObject.BackColor = "Red";
}
}
if (e.RemovedItems.Count > 0)
{
if (e.RemovedItems[0] != null)
{
oMyObject = (MySercvices.MyObjectDao)e.RemovedItems[0];
oMyObject.BackColor = "Black";
}
}
You can use simple colors like in the example, or you can use any predefined colors from your xaml

Check checkbox of selected rows within DataGrid

I have one datagrid, within which first column contains checkbox. What I want to implement is, when I check first row checkbox and then i check fifth row checkbox keeping shift button pressed then application should check all the checkbox of the selected rows (i.e. row first to fifth).
I am using MVVM pattern. I have checkall checkbox at the top of the checkbox column and command is binded to it. CheckAll checkbox working properly. Click on individual checkbox also executes command from the viewmodel which checks-unchecks selected checkbox. ViewModel's property is binded to checkbox.
What I want to do now is very similar what we see in mails (i.e. yahoo,gmail). Checkbox should check-uncheck base on row selection from keyboard using shift-key. Please inform me if I am missing out any required information for describing my issue.
Yup possible.
In your Datagrid that you used there is a property called SELECETIONMODE.
Set this to SelectionMode = EXTENDED,
Next->
Use this kind of code to check all the Checkboxes to true.
It is best to create a class of the data your loading. Makes it clean and easy.
If your using RIA services to load data and bind it to your datagrid your already sorted..:)
Instead of using column numbers i would recommend this highly.
private void refreshDatagrid()
{
ObservableCollection<Cars> c = --Load all your cars----;
this.mydatagrid.ItemsSource = c;
}
---To Check all the boxes
private void checkAllBoxes_Click(object sender, RoutedEventArgs e)
{
if (this.mydatagrid.SelectedItems != null)
{
foreach (Cars c in this.mydatagrid.SelectedItems)
{
if (c.isSelected != true)
{
ula.Approved = true;
}
}
}
}
--Example Object Class
class Cars {
public Cars(){}
public Nullable<bool> isSelected {get;set;}
public string carName {get;set;}
public string LicenseNumber {get;set;}
public string year {get;set;}
public string model {get;set;}
}
Of course finally Create a button in the frontend with Click="checkAllBoxes_Click"
Hope the concept is clear.
Cheers