C# :: Clear A Listbox From A Class?

Jun 5, 2014

I need to clear a listbox from a class other than the form where it exists. Why this isn't working? I'm getting no error messages when I compile and I am seeing the Console.WriteLine text I also added in the same function. I can call this function from within my form and it behaves as expected. I tried setting the listbox to public despite the fact I wasn't getting protection level errors but that made no difference.

Just to clarify what I'm doing here... I have a form that includes a panel of user controls from another class. So there is a listbox on OtherClass and the listbox is in MyForm. Heres my code:

MyForm

public void ClearListBox() {
Console.WriteLine("echo");
listBox.Items.Clear();
} OtherClass
private void listBox_SelectedIndexChanged(object sender, EventArgs e) {
MyForm mf = new MyForm();
mf.ClearListBox();
}

View 9 Replies


ADVERTISEMENT

C# :: Send Value From Class To Listbox?

Mar 3, 2014

i've a function to add many buttons to TabbedPanel like is visible here

public void AddBeverageDrinkstoTabbedPanel(TabPage tp1, ListBox lst1) {
food getbeverage = new food();
string[] bev_product = getbeverage.name1;
FlowLayoutPanel flp1 = new FlowLayoutPanel();
flp1.Dock = DockStyle.Fill;
foreach (string value in bev_product)

[code].....

What happens? When i click in any button, want add an specific text to listbox and to do this i builded an method called beverageclick(), with these code:

public void beverageclick(object sender, EventArgs e) {
Button b = (Button)sender;//button sender
string value = (string)b.Tag;// value = b.tag (tag of sended button tag = value (value of AddBeverageDrinkstoTabbedPanel) method)

[Code] ....

What is wrong? how can i add an specific value when an button was clicked.

View 1 Replies View Related

C# :: Moving Listbox Selection To New Listbox In New Form?

Sep 11, 2014

Okay so i have everything right accept transfering the selectedindex from listbox in form1 to listbox in form2. I am using the below string item to hold the selected line of the list box, with the intent of recalling and then adding it into the form2 listbox. I get a not implemented error and i can't figure out why. I know the information is moving with the variable item, it just doesn't get printed out to the new listbox.

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string item = listBox1.SelectedItem.ToString();
Form2 form2 = new Form2();
form2.Show(item.ToString());

[Code]....

View 13 Replies View Related

C/C++ :: How To Clear Nested Stl Map

May 21, 2013

here is a nested stl map

typedef struct struct_RISCP {    
        float nSCPTotal;
        int nSCPCount;
        CString strIMEI;  
        std::map<UINT8, int> mapSection;    
    }RISCPSt;
map<stRncCellIdntyDmnType, RISCPSt>m_mapRISCP;

it occupied too much memory,i wanted to clear them(both outer map and inner map) ,some one told me you just need to call m_mapRISCP.clear(),then the mapSection (inner map) will be cleared automaticly,in other words, m_mapRISCP.clear() will clear both outer map and inner map.

View 5 Replies View Related

C++ :: Clear Screen Without Blinking

Nov 4, 2013

I have a one simple question :D. I want to output to the console some symbols. Let's say that i have a loop.

for(int i = 0; i < 10; i++) cou << "* ";

Then I want to output other symbols but I want to overwrite the previous symbols. I know I can use system("cls"); but it blinks if I try to output the same characters. For example if I have:

for(int i = 0; i < 10; i++) cou << "* ";
system("cls");
for(int i = 0; i < 10; i++) cou << "* ";

After I run this code the first loop outputs ten "*". Then there is a blink and there are again ten "*" shown. How can I avoid this blink?

View 4 Replies View Related

C++ :: Difference Between Erase And Clear

Apr 4, 2014

vector<int> *vec; allocate memory and

suppose vec conatins 10 values then

erase(vec->begin(),vec->end());

vec.clear();

both should be used or any one one is fine to erase all ??

View 1 Replies View Related

C++ :: Clear Part Of The Screen?

Nov 3, 2014

Is there any way I can clear only a selected part of the screen? (I'm aware of system("cls"))

For example, when you enter a date, and is wrong, could it just errase that input and only say "Wrong try again" without errasing everything else you where doing?

In this case, a function that only errases what is in the while

while(not wrong)
{
cout<<"DIA: ";
cin>>obj.dia;
cout<<"MES: ";
cin>>obj.mes;
cout<<"ANIO: ";
cin>>obj.anio;
}

PS: Also, is there any whay in which you can ask the user to enter the date DD/MM/YYY?

View 1 Replies View Related

C/C++ :: Clear First Character Of Array

Mar 26, 2014

I am trying to clear the first character of my array. The first two methods don't seem to work. The third method seems to but doesn't look like a good idea.

char operand[] = "abc";
//both methods seem to null it out
operand[0] = 0;
memset(operand, 0, 1);
printf("%s", operand);

//seems to work
memset(operand, 5, 1);

View 4 Replies View Related

C++ :: How To Clear A File At Beginning Of Program

Jul 28, 2013

I'm writing a program that converts hex to letters and writes the letters to a file.To write I'm currently using ofstream("output.txt" ios::app)But the issue with this is, is that everytime I run the program, it appends and doesn't write from the beginning of the text file.So what I want to know is, how do I clear the contents of a text file, before writing to it?

View 1 Replies View Related

C++ :: Clear Data From Char Array?

Feb 5, 2013

How to clear data from a char array?

View 19 Replies View Related

C++ :: How To Clear Exception Mask For A File

Feb 12, 2015

When creating an exception mask for a file, should an exception throw during a file operation, I can reset the state bits of the actual file using ios::clear().

Though after doing so, will the exception mask still throw an exception, thinking that the specified error state flags are still set to true? If so, how can I reset the exception mask so that it is ready to throw more exceptions should the appropriate situations arise in the future?

View 2 Replies View Related

C++ :: Osstream Doesn't Flush Or Clear

Dec 15, 2012

Code:
std::ostringstream ss;
ss.flush();
ss.clear();
ss << v.x;
std::string buff(ss.str());
XMLString::transcode(buff.c_str(), tempStr, 99);

[Code] ....

The buff at "Z" are stringed together with previous values. How do I resolve that?

View 5 Replies View Related

C++ :: Using Clear Device And Sleep Functions In Graphics

Dec 14, 2014

I have a college project which is a car racing game using C++ and the old-school graphics library BGI. After I draw the map and placed the objects(Car,obstacles,road's borders etc..)I added Sleep(); function to the function named Obstacles(); but the problem is, I can't move the car with the right&left arrows.a

Another problem,If I added a cleardevice(); command all objects disappears only the obstacles function keeps working. the Code is here:

char c;
do{
c = (char)getch();
if (c == KEY_LEFT) {
x = x - 10, x1 = x1 - 10;
} if (c == KEY_RIGHT) {
x = x + 10, x1 = x1 + 10;

[code].....

note: this is not the whole code, it's only a small portion of it, not a debugging question only need a hint how to fix it.

View 3 Replies View Related

C++ :: Clear Screen For Microsoft Visual 2010?

Jan 11, 2013

I checked through the net and most of the solution like clrcr(); is not working for microsoft visual 2010. SO i was wondering for those who was using the same ver of c++ as me how do you clear the screen?

View 5 Replies View Related

C# :: Datagridview Combobox Selection Clear After Adding New Row

Dec 25, 2014

I have 2 datagridview in one windows form, When I click row from datagridview1, it shows in datagridview2 (Select *from....). Also I have combobox column in datagridview2. My question is, when I select items in combobox, and click to new row in datagridview 1, datagridview2 combobox's is getting empty. it is my code:

private void dataGridView1_CellDoubleClick_1(object sender, DataGridViewCellEventArgs e) {
try {
int id = Convert.ToInt32
(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["id"].Value);//3

[Code] .....

View 8 Replies View Related

C# :: Clear White Space On Random Tile Map

Mar 14, 2015

I've got myself a 2d array

int[,] map = new int[100,100];

I've populate that will a bunch of 1's and 0's. The 1 represents a wall, and a 0 is dirt.

I'm looking for a way to clean up my blank spaces outside of my walls. Any algorithm I can use to identify these big areas and replace them with a '1'

for (int y = 1; y < map.GetLength(1) - 1; y++) {
for (int x = 1; x < map.GetLength(0) - 1; x++) {
// Inside here is where I was hoping to archive my work
bool draw = true;
foreach (Room room in rooms)

[Code] ....

Attached is an example of my output.As you will be able to see, there is a lot of brown. I want to fill the brown with walls, but leave space for a path between the rooms.The 'draw' bool is true when I'm outside of a room, just so I don't start throwing walls inside my room.

Example of what the array would look like (for those who don't know)

int[,] map = new int[100,100]
{
{0,1,1,1,1,1,0},
{0,1,0,0,0,1,0},
{0,1,0,0,0,1,0},
{0,1,0,0,0,1,0},
{0,1,0,0,0,1,0},
{0,1,1,1,1,1,0},
};

View 6 Replies View Related

C++ :: Clear Screen In Console - Change Text Color In EXE

Dec 28, 2013

How I can clear the whole screen in console...

And I'm using clrscr(); and its not working.

How i can change the text color in the .exe without using system function

View 4 Replies View Related

C/C++ :: Simple Calculator - Clear Screen Following User Input

Dec 10, 2014

I am working on a simple calculator in C++ .... All works fine with the calculator up until the requirement for the user to input "do you want to go again y/n" .... What i want to happen is the screen to clear down and reloop to the enter name part....but i can't get it to do that

Program Description: To write and develop a programme where a user can input a cost or price of something before VAT our program must then process the input number and must output the price with the original value plus VAT

#include <iostream>// I must use this to start my programming
#include <string> // I have added this for the extension task so the user has to input their name
#include <iomanip> // this is to manipulate the text
#include <stdlib.h>
using namespace std; // using the "using namespace std" shows that i will be using standard text throughout this programme

[Code] .....

View 5 Replies View Related

C :: Finding Percentages / If Statement / Clear Screen And Reloading Program

Nov 11, 2013

For my C programming module, I've been asked to create a program which is basically a ten question mathematics quiz or test if you like. Below is a copy and paste of my current, working program.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main () {

[Code]....

I am also trying to include into my program; If the user achieves 4 or less marks in the test, they are asked if they would like to repeat the test (have a second chance).

I have been asked by my Lecturer to ask the Question; "Would you like to try again" and the response is 'Y' for yes, 'N' for no. Would this be shown by:

char Y = Y;
char N = N;
printf("Would you like another go?");
scanf(%d%, &Y, &N);

And finally; If the user would like another go, then I am trying to include the code that clears the screen and then reloads the program?

What code is used to clear the screen and no clue what code is written to refresh or reload the program. I assume it's a loop statement or some sort.

View 1 Replies View Related

C# :: Using Array In Listbox?

Jun 2, 2014

My main form I have the following code

[ImportingConstructor]
public MainForm([ImportMany] IEnumerable<AudioPlugin> content)
{

[Code].....

However, when I add to the listbox as shown above in my main form code the results all show on the same line. My understanding was that they should all be treated as separate because of foreach loop but apparently that is incorrect. I have seen mixed things online some showing that its required to use AddRange instead of Add, however, after literally hours of trying to make this work I am still coming up with nothing. I can't seem to get any code to work using the AddRange or am I finding any way to output each results on a separate line.

View 7 Replies View Related

C++ :: Listbox SendMessage Not Working

Jun 25, 2013

I have a problem with SendMessage. Anything I send doesn't show up but instead empty lines appear. What is wrong with my code?

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR greeting[] = _T("Hello, World!");
wchar_t listBoxStr[15];

[code].....

View 7 Replies View Related

C# :: Invert ListBox Selection?

Apr 18, 2014

I have my ListBox working and I'm able to select the items I want to keep. I'm trying to now get the Invert of the current selection for the items to delete.

I tried using:

if (lstLinePatterns == null) return;
for (int i = 0; i < lstLinePatterns.Items.Count; i++)
lstLinePatterns.Items[i].Selected = !lstLinePatterns.Items[i].Selected;

But
.Selected
is giving me an object error.

Is there an easy way to just inverse current selection?

Current Code:

private void btnSelectNonRvt_Click(object sender, EventArgs e)
{
// Unselects any Items to Prevent Infinite Loop
lstLinePatterns.SelectedIndex = -1;

[Code]....

View 3 Replies View Related

C# :: Two Checked Listbox - One Interacts With Other

Aug 31, 2014

I am working on a Windows From application on Visual Studio 2010 where i need to use two checkedlistbox that interacts one with the other one. Let say that the first checkedlistbox is for world regions (i.e.):

Asia
Africa
Europe
South America

And let say that the second checkedlistbox is for Countries (i.e.):

Spain
Italy
Romania
Monaco

(all of this belongs to Europe region)

What we need to do is that when the user check on any world region it automatically checks all the countries on that region in the second checkbox, and vice versa if the users check any country on the second checkedlistbox it automatically seconds the region on the first one.

I know that is possible in Java and we know how to do it, but i don't know if C# supports this and how to do it. I was looking on the class information in the microsoft website: [URL] .... but not a concrete example on how to do it.

View 5 Replies View Related

C# :: Listbox Loop - Getting Value Of Both Cards

Apr 3, 2015

I have a lstYourHand that has two cards in it, I loop through the listbox to get the values of both cards. I take the string value of the listbox item (strCardVal) and use a switch to give it an integer value (intCardVal). For some reason, when I run the code, the message Box at the end gives me the value 0 as a result, it does not register me giving it a value in the switch statement. My code is below:

Int32 intCardVal = 0;
String strCardVal;
Int32 intLoopCounter1;
for (intLoopCounter1 = 0; intLoopCounter1 == 1; intLoopCounter1++) {
strCardVal = lstYourHand.SelectedItem.ToString();

[Code] .....

View 3 Replies View Related

C# :: Removing Items From ListBox

Mar 5, 2014

I'm working on creating a windows form with a listbox, textbox, and 2 buttons (add,remove). I need a way of removing every string matching the contents of the textbox from the listbox. Here's what I have:

for (int i=0;i<listBox1.Items.Count;i++)
{
//...
listBox1.RemoveAt(i--)
}

Seems to work, but I need a way to show a error message once the user clicks 'remove' and no items in the listbox match.

View 6 Replies View Related

C# :: Cannot Set Font Size For A Listbox

Jun 24, 2014

I was working with a richTextBox on setting its font, color and size. I found examples and got that to work. It seems like a kludge to me just to get the size set.

So, now I need to do the same for a listBox. I got the font and color set but cannot get the font size set.

The error I am getting is on line 6 below: listBoxTopLevelChecklist.Font.Size = fontDialog.Font.Size;

VS 2013 Express tells me this property (font.size) is read-only. That was the same error I got on the richTextBox until I found way using the .SelectionFont structure, but the listBox doesn't support that. So, I'm stuck.

Line 8 on is working finr for the richEditBox.

DialogResult result = fontDialog.ShowDialog();
if (result == DialogResult.OK) {
listBoxTopLevelChecklist.Font = fontDialog.Font;
listBoxTopLevelChecklist.ForeColor = fontDialog.Color;
listBoxTopLevelChecklist.Font.Size = fontDialog.Font.Size;

[Code] .....

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved