how to delete items on selecting item through listbx - c#-4.0

I am making desktop application using C#.NET and SQL SERVER 2008.i have taken a listbox in a form containing elements which is fetched from database.Now i want that on selecting the item which is present in the listbox should get delete I have taken a delete button
i have listbox name listbox1 containing items and btndelete to delete

Here is a button click handler that will delete the currently selected item in the listbox:
btnDelete_Click( object sender, EventArgs e )
{
listBox1.Items.Remove(listBox1.SelectedItem);
}

Related

Accessing Microsoft Forms 2.0 Frame Controls in VBA

I found out that the only way to have controls be visible in a Frame in Excel is to add them with right-mouse-click Edit. But when I do this the controls are not listed in VBA.
These are the controls on the worksheet:
The first option button is optToday, the first textbox txtToday, the second option button optDate, the second textbox txtDate. The frame is groupDate, the button cmdGetWeek, the third textbox is txtWeekofMonth.
But this is all that comes up in VBA:
I am looking to call a function to calculate week of month when the user clicks on the button. If the user selected today this is the date that will be sent to the function. If the user selected a different date that will will be sent instead.
What I have so far for the code is this:
Private Sub cmdGetWeek_Click()
Dim selectedDate As Date
Dim calcWeekNum
If (optToday.Value = True) Then
selectedDate = txtToday.Value
Else:
selectedDate = txtDate.Value
End If
MsgBox ("Selected: " & selectedDate)
calcWeekNum = WeekOfMonth(selectedDate) End Sub
I get a Run-Time Error '424' for "If (optToday.Value = True) Then".
What is the correct way of accessing the frame controls?
It's unclear whether you added a Form Frame or an ActiveX Frame.
Form Frames are insertable, by default, from the Insert menu:
In order to be able to handle control events in VBA, you need to use the ActiveX form of the Frame control... But by default, the Frame ActiveX control isn't visible on the Insert menu. You'll need to press the More Controls button:
And then choose Microsoft Forms 2.0 Frame Control from the list of controls:
You'll then need to ensure that you add the ActiveX form of the Option Buttons and other controls... All of the controls (and their events), including the Frame and the Option Buttons will then appear in the Worksheet's event drop-down.

Get ComboBoxItem from Combobox

In my universal windows Application I have below "xaml" :
<ComboBox Margin="8" Header="Language" x:Name="cmbLanguage" x:Uid="cmbLanguage" ItemsSource="{x:Bind Languages}" SelectionChanged="LanguageComboBox_SelectionChanged"/>
Now i need to iterate through my combobox and get the combobox items to disable some of them. How can i get access to the items from code behind?
Now i need to iterate through my combobox and get the combobox items to disable some of them. How can i get access to the items from code behind?
You could get ComboBoxItem with ContainerFromIndex method, and the set IsEnabled property to false or true, for more you could refer to the follow.
ComboBoxItem^ item = dynamic_cast<ComboBoxItem^>(cmbLanguage->ContainerFromIndex(CurrenIndex));
item->IsEnabled = false;

How to access a FormControl checkbox in an Excel sheet using OpenXML SDK

I have a spreadsheet that has a number of check boxes in various cells on the sheet that I need to get the value of (checked/unchecked) from within a c# program.
I'm using the OpenXML SDK v2.5 and the associated toolbox.
Using the toolbox I can see the check box controls as part of the AlternateControlParts collection. These are not ActiveX checkboxes but are form controls added via the developer tab in Excel.
When I use the SDK I can also see the WorkSheetPart which has a ControlPropertiesParts collection on it which lists all the checkboxes.
My problem is, how do I find which checkbox is in which cell or at least related to which cell?
I have also found the collection
wsPart.ControlPropertiesParts.First().DrawingsPart
.WorkSheetDrawing.DrawingsPart.WorkSheetDrawing
This collection appears to have the alternate content of each of the checkboxes and if I drill down further I can find the anchor points which appear to give the location of the checkboxes relative to the cells on the sheet. However, the col and row Id’s don’t appear to exactly match up and I suspect that the Offset values may also have something to do with it.
If someone can point me in the right direction on how to map the checkboxes to the correct row/cells I would be very grateful.
Thank you for any help.
Regards
Paul
I have a solution, it contains only the logic (The property FormControlProperties is available since Office 2010:
SpreadsheetDocument document;
string sheetName = "sheetName";
string controlName = "Option Button 5";
...
var wbPart = document.WorkbookPart;
var theSheet = wbPart.Workbook.Descendants<Sheet>().FirstOrDefault(s => s.Name == sheetName);
var wsPart = (WorksheetPart)wbPart.GetPartById(theSheet.Id);
var control = wsPart.Worksheet.Descendants<DocumentFormat.OpenXml.Spreadsheet.Control>().FirstOrDefault(c => c.Name == controlName);
var controlProperies = (ControlPropertiesPart)wsPart.GetPartById(control.Id);
bool isChecked = controlProperies.FormControlProperties.Checked == "Checked";
But it is simplier to map the FormControl value to a cell and read the cell value if the you can edit the excel file.

c# listbox i have trouble with

I created a list in a button ADD:
{
List <string> Names = new List<string>();
Names.Add(textBox1.Text);
textBox1.Text = " ";
}
I created another button SHOW NAMES and i want these names I entered in the list, to be listed in the listbox? How can this be done?
First, you need to move that first line outside of the button click method, because if you declare the list inside the method, it will be gone once that method returns.
For your SHOW NAMES method, if all you want to do is display the list, you could use a TextBlock instead of a listbox, and it will be a little easier:
TextBlock tb = new TextBlock();
tb.text = string.Concat(Names);

how to get selected item of combo box

i'm using lwuit with j2me . how to get combo box selected item or index? i found the function for setSelectedIndex but not for getting the selected.
Use this code :
comboBox.getSelectionModel().getSelectedIndex();
To return the current selected offset in the list.
comboBox.getSelectionModel().getSelectedItem();
To return the current selected item in the list or null for no selection
To get what you selected as a string:
String selected_text = ComboBox.getItemAt(ComboBox.getSelectedIndex());

Resources