public Sql() { if (instance == null) { Log.ErrorAt("IA.Sql", "IA not initialized"); return; } info = instance.info; defaultIdentifier = instance.defaultIdentifier; }
public Sql(SqlInformation info, string defaultIdentifier) { this.info = info; if (defaultIdentifier == "") { this.defaultIdentifier = ">"; } else { this.defaultIdentifier = defaultIdentifier; } instance = this; }
private void Form1_Shown(object sender, EventArgs e) { var dataOperations = new SqlInformation(); var contacts = dataOperations.GetOwnerContacts(); ownerContactListView.BeginUpdate(); foreach (var contact in contacts) { ownerContactListView.Items.Add( new ListViewItem(contact.ItemArray) { Tag = contact.CustomerIdentifier }); } ownerContactListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); ownerContactListView.EndUpdate(); // this is how to select the first item //ownerContactListView.FocusedItem = ownerContactListView.Items[0]; //ownerContactListView.Items[0].Selected = true; /* * This is a hard coded example to find an item and ensure it's visible */ var item = ownerContactListView.FindItemWithText("Santé Gourmet"); if (item != null) { var index = ownerContactListView.Items.IndexOf(item); ownerContactListView.Items[index].Selected = true; ownerContactListView.EnsureVisible(index); } ActiveControl = ownerContactListView; }
private void Form1_Shown(object sender, EventArgs e) { var dataOperations = new SqlInformation(); var categories = dataOperations.Categories(); var categoryIndex = 1; // ReSharper disable once TooWideLocalVariableScope var groupName = ""; foreach (var category in categories) { var products = dataOperations.Products(category.CategoryId); /* * Some category names have unwanted characters and/or whitespace, remove these chars. */ groupName = category.Name.Replace("/", "").Replace(" ", ""); var currentGroup = new ListViewGroup(category.Name, HorizontalAlignment.Left) { Header = category.Name, Name = $"{groupName}Group{categoryIndex}" }; categoryIndex += 1; ProductListView.Groups.Add(currentGroup); foreach (var product in products) { var listViewProductItem = new ListViewItem(new[] { product.ProductName, product.Supplier, product.Phone, product.UnitPrice.ToString(), product.UnitsInStock.ToString() }, -1) { Group = currentGroup, /* * Contains primary and foreign keys for current product */ Tag = product.IdentifiersTag, /* * Required to change font and ForeColor below */ UseItemStyleForSubItems = false }; /* * Alter user that the product is not available. * Could have excluded the product, that would be dependent * on business requirements. Also reorder information could * be presented. */ if (product.UnitsInStock == 0) { listViewProductItem.SubItems[4].ForeColor = Color.Red; listViewProductItem.SubItems[4].Font = new Font( listViewProductItem.SubItems[4].Font.FontFamily, listViewProductItem.SubItems[4].Font.Size, FontStyle.Bold); } ProductListView.Items.Add(listViewProductItem); } } ProductListView.FocusedItem = ProductListView.Items[0]; ProductListView.Items[0].Selected = true; ActiveControl = ProductListView; ProductListView.ItemSelectionChanged += ProductListView_ItemSelectionChanged; ProductListView.ItemCheck += ProductListView_ItemCheck; GroupsComboBox.DataSource = ProductListView.Groups.Cast <ListViewGroup>().Select(lvg => lvg.Name).ToList(); }