|
Hi!
I am trying to add different values to a combobox in a datagridview.
|TEXTColumn | |TEXTColumn | |TEXTColumn |DataGridViewComboBoxColumn |
|John | |Svensson | |1231421 |Cat |
| | | | | |Dog |
| | | | | |mouse |
|Sarndra | |Larsson | |2344324 |horse |
| | | | | |Bird |
|Adam | |Jönsson | |6587568 |dog |
| | | | | |mouse |
| | | | | |badger |
| | | | | |Tiger |
i set up a data grid view,
private void SetUpforDataGridView()
{
dataGridViewSearched.ColumnCount = 3;
DataGridViewComboBoxColumn dataGridViewcombobox = new DataGridViewComboBoxColumn();
}
And then set the values, it works dine for the textfields but not for the combobox, i get no values in it
public void BindUserList(List<User> userList)
{
object[] row = new object[3];
foreach (User p in userList)
{
row[0] = p.LastName;
row[1] = p.FirstName;
row[2] = p.UserId.ToString();
dataGridViewSearched.Rows.Add(row);
foreach (var unit in p.UnitActivationPeriods)
{
((DataGridViewComboBoxCell)dataGridViewSearched.Rows[dataGridViewSearched.Rows.Count - 1].Cells[5]).Items.Add(unit.ToString());
}
Any thoughts?
Mjelten
|
|
|
|
|
You should set the DataSource of the DataGridViewComboBoxColumn to your list of options. Then use the DisplayMember and ValueMember properties to set what is displayed and what is stored.
For examples Google for datagridview lookup column. there are loads of 'em.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
So you cannot display items without using datasource?
|
|
|
|
|
I am not aware of any way to do it, if it is possible.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi! My code works fine...I just had to change the property of the datagrid to readonly = true;
|
|
|
|
|
Good stuff!
I must make a note of that.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi i have a problem with datagridcomboboxcolumn... i think that i can't give to DataPropertyName the value of a string field in my table, cause it displays me nothing T.T so... the main problem, i think it is because the form with the datagridviewcomboboxcolumn is opened from an MDI parent... that's the problem because when i open the form just normally, the datagridviewcomboboxcolumn displays me the data... What Can i do??? i need help with that
|
|
|
|
|
You should post this question as a new message.
It is considered rude to try to hijack someone else's thread.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
ok i will... sorry...
|
|
|
|
|
H! All
I have a problem starting window service..i made some adjustment in this existing window service program..i changed the connection string to connect to Oracle(from app.config)..I also added the Oracle Data.Access in the references..and also installed ODT with ODAC 11.1.0.621 driver Oracle.Data.AccessClient in references). From OnStart, it calls a function LLProcess, from there it connects to a web service to execute another function that gets data from SQL Server 2005 and then return it as xml data..and then process this data to save in the oracle database..I tested the program and it was running fine..It can get xml data and saves it to Oracle database. I rebuilt the existing installer and installed it, but when i tried to start it from services, an error pops up..("error 1053: The service did not respond to the start or control request in a timely fashion"). The program uses System.Threading..
I don't know where the error came from..is it the Oracle references might causes the problem? DLL's?
Another thing is that i can execute(or double click) the EXE file manually after the installation and it was running successfully. If that is the case, is it normal for a window service EXE to be run manually?
BTW, The existing program was previously connecting to AS400 and was running in our production server already..
Anyone please help! Thanks!
Regards
|
|
|
|
|
May be some references are missing....
Also,try to catch the error and write into log file.So that exact error can be found
himanshu
|
|
|
|
|
thanks for the reply...
i already tried to write to a log file..when i started the service, it passes the process..but did not passed thru error handler(catch)..it just loop and loop in the function..and i think when it reaches 100+ loops(that's when the progress bar in the service reaches its half value), the error pops up..
What are the possible references that i missed?
Thanks and regards
|
|
|
|
|
Hi
I have two points to ask
(1)obrix_activex wrote: it passes the process..but did not passed thru error handler(catch)..it just loop and loop in the function
In which function this loop is going on?
(2)You have written try catch block in OnStart only?
himanshu
|
|
|
|
|
Nope..I have a function called LLPlusProcess...
This some content of OnStart..
intervalEnqueue = 600;
timer1 = new Timer(new TimerCallback(LLPlusProcess), null, intervalEnqueue, intervalEnqueue);
then inside the LLPlusProcess function it loops..waiting for some data to retrieve from SQL server..
Problem is that after how many loops an error pops up(this error pops up when i start the window service in the services.msc...
|
|
|
|
|
Have you write try catch block in LLPlusProcess function.
your best bet to solve this is try to write key steps in log file like
When you call LLPlusProcess function,Inside LLPlusProcess function and when LLPlusProcess function ends.Just try to find upto which point your code is executed by reading log file.
himanshu
|
|
|
|
|
Check the connection string. Is that correct?
|
|
|
|
|
I think so because during debug mode..i can connect to oracle (save and retrieve the data)... the only problem is that when i installed it and tried to start it in the services.msc..it has an error mentioned in my previous message..
|
|
|
|
|
How many times are you going to ask this?
What does your OnStart method lok like now?
|
|
|
|
|
ok..this is the whole code in service1.cs..error or time out comes inside the function LLPlusProcess for how many loops..i dont know if it uses too many thread..please help..tnx!!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OracleClient;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
//using System.Timers;
using System.Threading;
using System.Net.NetworkInformation;
using System.IO;
namespace LLPlus
{
public partial class Service1 : ServiceBase
{
Timer timer1;// enqueue
Service service;// = new Service();
string refIDEQ = null;
bool enqued = false;
string strconn;
OracleConnection conn;
OracleCommand cmd;
public Service1()
{
InitializeComponent();
}
public void InitializeConnection()
{
strconn = System.Configuration.ConfigurationManager.ConnectionStrings ["OracleConnection"].ToString();
conn = new OracleConnection(strconn);
cmd = new OracleCommand();
}
public void Start()
{
int intervalEnqueue;
try
{
InitializeConnection();
if (Int32.Parse(System.Configuration.ConfigurationManager.AppSettings["enqueueDelay"]) > 0)
{
intervalEnqueue = Int32.Parse (System.Configuration.ConfigurationManager.AppSettings["enqueueDelay"]) * 1000;
timer1 = new Timer(new TimerCallback(LLPlusProcess), null, intervalEnqueue, intervalEnqueue);
}
else
{
AddToFile("Start...");
intervalEnqueue = 600;
timer1 = new Timer(new TimerCallback(LLPlusProcess), null, intervalEnqueue, intervalEnqueue);
}
}
catch (Exception e)
{
System.Diagnostics.Debug.Write("\r\n[Start] Error: " + e.Message);
}
}
protected override void OnStart(string[] args)
{
Start();
}
protected override void OnStop()
{
timer1.Dispose();
conn.Close();
}
public void LLPlusProcess(object state)
{
System.Diagnostics.Debug.Write(" LLPlus [ENQUEUE] : Service Started at " + DateTime.Now.ToString() + " \r\n");
if (!enqued)
{
try
{
enqued = true;
GetSMSResult getIncomingSMSResult = new GetSMSResult();
getIncomingSMSResult = null;
service = new Service();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
getIncomingSMSResult = service.GetSMS(System.Configuration.ConfigurationManager.AppSettings["clientAppKey"], System.Configuration.ConfigurationManager.AppSettings["enqueueStatus"], "Waiting", Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["enqueueRecord"]));
string getIncomingSMSResultResponse = getIncomingSMSResult.ResponseMessage;
System.Diagnostics.Debug.Write(getIncomingSMSResultResponse + "\r\n");
GetSMSResultMessage[] getIncomingSMSResultMessage = null;
getIncomingSMSResultMessage = getIncomingSMSResult.Message;
if (getIncomingSMSResultMessage != null)
{
System.Diagnostics.Debug.Write(getIncomingSMSResultMessage.Length + "\r\n");
for (int x = 0; x < getIncomingSMSResultMessage.Length; x++)
{
System.Diagnostics.Debug.Write(getIncomingSMSResultMessage[x].DateReceived + "\r\n");
System.Diagnostics.Debug.Write(getIncomingSMSResultMessage[x].Keyword + "\r\n");
System.Diagnostics.Debug.Write(getIncomingSMSResultMessage[x].MessageText + "\r\n");
System.Diagnostics.Debug.Write(getIncomingSMSResultMessage[x].ReferenceID + "\r\n");
System.Diagnostics.Debug.Write(getIncomingSMSResultMessage[x].Sender + "\r\n");
System.Diagnostics.Debug.Write("COUNTER " + x + "\r\n");
try
{
refIDEQ = getIncomingSMSResultMessage[x].ReferenceID;
string sql = "INSERT INTO PLP_ENQUE_DEQUE(ref_id,service_no,keyword,msg_in,status) "
+ " VALUES ('" + getIncomingSMSResultMessage[x].ReferenceID + "','" +
getIncomingSMSResultMessage[x].Sender + "','" +
getIncomingSMSResultMessage[x].Keyword + "','" +
getIncomingSMSResultMessage[x].MessageText + "','E')";
conn.Open();
cmd.Connection = conn;
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
int recAffected = cmd.ExecuteNonQuery();
conn.Close();
if (recAffected > 0)
{
string updateSMS = service.UpdateSMSStatus(System.Configuration.ConfigurationManager.AppSettings["clientAppKey"], getIncomingSMSResultMessage[x].ReferenceID, System.Configuration.ConfigurationManager.AppSettings["enqueueSuccessMsg"]);
System.Diagnostics.Debug.Write(" UPDATE SMS : " + updateSMS + "\r\n");
}
else
{
string updateSMS = service.UpdateSMSStatus(System.Configuration.ConfigurationManager.AppSettings["clientAppKey"], getIncomingSMSResultMessage[x].ReferenceID, System.Configuration.ConfigurationManager.AppSettings["enqueueFailedMsg"]);
System.Diagnostics.Debug.Write(" UPDATE SMS : " + updateSMS + "\r\n");
}
}
catch (Exception icmsEx)
{
System.Diagnostics.Debug.Write("ENQUEUE [EX] 2: " + icmsEx.ToString());
if (icmsEx.Message.ToLower().StartsWith("unspecified error"))
{
InitializeConnection();
}
else
{
string updateSMS = service.UpdateSMSStatus(System.Configuration.ConfigurationManager.AppSettings["clientAppKey"], getIncomingSMSResultMessage[x].ReferenceID, icmsEx.Message);
System.Diagnostics.Debug.Write("ENQUEUE [ICMSEX] " + icmsEx.ToString());
}
}
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.Write("ENQUEUE [EX] : " + ex.ToString());
}
System.Threading.Thread.Sleep(100);
enqued = false;
}
else
{
System.Diagnostics.Debug.Write("\r\n ---- ENQUEUE PROCESS ON GOING ----\r\n ");
}
}
}
}
|
|
|
|
|
For my Windows Services, I set the database connections in the constructor.
Ideally your OnStart and OnStop methods would only be:
public void OnStart()
{
timer1.Start() ;
}
public void OnStop()
{
timer1.Stop() ;
}
I add some logging as well, but the point is that you want to be doing very little in these methods; it's not the place to be setting up a database connection.
0) Set up the connection in the constructor
1) Start the timer in OnStart
2) Stop the timer in OnStop
3) In the timer callback method (LLPlusProcess?): open the connection, use it, and close it.
After further reading of your code, I think you may have bigger problems, but start with that and see how it goes.
|
|
|
|
|
I have a pretty simple FileSystemWatcher setup as follow:
var sw = new FileSystemWatcher();<br />
sw.Path = dir;<br />
sw.Filter = "*";<br />
sw.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName;<br />
sw.Changed += new FileSystemEventHandler(OnChanged);<br />
sw.Created += new FileSystemEventHandler(OnChanged);<br />
sw.Deleted += new FileSystemEventHandler(OnChanged);<br />
sw.Renamed += new RenamedEventHandler(OnRenamed);<br />
sw.EnableRaisingEvents = true;<br />
The unfortunate thing is, when I open a file with Notepad, edit it and save, I got 2 Changed event.
How come? what should I do to get only 1 event?
Any ideas or link!?
PS: I'm running Vista Ultimate x64
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
I used a stupid hack.
I made a table of last access.
If it's less than 1s ago, I do nothing...
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Hi,
FileSystemWatcher is not perfect; it typically fires multiple times when something happens to a file, often because one user action causes several technical operations on the directory entry: a file gets created/opened, data gets written, when the file gets flushed or closed some metadata gets updated, etc.
AFAIK there is nothing you can do against that, if you only want one event, you have to take whatever number of events coming at you and filter them yourself.
And the most useful feature is missing, it would fire an event (just one!) when one is done acting on a file, the way it operates right now is it fires from the beginning of an action, so one never is sure the file isn't in some intermediate state.
BTW: FileSystemWatcher also may drop some events, e.g. when there is much activitity going on in your watched folder.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Good to know!
Anyway I am watching human edited config file, so I should be ok!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
HI Experts
I m inserting image in DB.I have made connection object and passed con. string in it....when my control comes to Executnonquery it gives me error as ->
ExecuteNonQuery: Connection property has not been initialized.
I m not getting the solution to it....
|
|
|
|