|
I have a DataGridView with three columns (checkbox, text, int). The text and int columns are bound to data from a data source. I want to manipulate in c#, which of the checkbox rows should be checked. I have the below code, however setting the value of the checkbox to true isn't displaying the required checkboxes as checked. Does anyone know how I could implement this?
…
dgvMultiCodes.AutoGenerateColumns = false;
dgvMultiCodes.DataSource = oCodeList.Table;
string SQLState = ChcekedSQLStatement();
SortedList<int, string> slCodeList = new SortedList<int, string>();
int codeCD = 0;
string desc = "";
oCodeList.GoTop();
while (!oCodeList.EoF)
{
codeCD = oCodeList.GetInteger("CD");
desc = oCodeList.GetString("DEF");
slCodeList.Add(codeCD, desc);
oCodeList.Skip();
}
bool bChecked = false;
##DataReader checkedList = new ##DataReader(SQLState, currentUser.oConnection);
while (checkedList.Read())
{
bChecked = slCodeList.ContainsKey(checkedList.GetInteger("KEYCODE"));
if (bChecked)
{
foreach (DataGridViewRow row in dgvMultiCodes.Rows)
{
if (row.Cells[dgvCodeCol.Index].Value.ToString() == checkedList.GetString("KEYCODE"))
{
row.Cells[dgvCheckCol.Index].Value = true;
break;
}
}
}
bChecked = false;
}
…
|
|
|
|
|
Maybe the code I provided was a little long winded. The line of code that isn't displaying the checkbox as checked is...
row.Cells[dgvCheckCol.Index].Value = true;
Is there some other property of the checkbox cell that I need to set or do I need to refresh the cell for the checkbox to appear checked?
Thank you
|
|
|
|
|
Hello Every one,
how can i insert duplicate value in HashSet
|
|
|
|
|
You can't, by definition: The HashSet<(Of <(T>)>) class provides high performance set operations. A set is a collection that contains no duplicate elements, and whose elements are in no particular order.
|
|
|
|
|
You can't. Would the negative of the value work for you?
Or use a Dictionary with a count of how many of the item you have.
Or a Dictionary with a List of the duplicate items.
modified 5-Mar-12 8:20am.
|
|
|
|
|
If you must insert duplicates, then you are using the wrong type. Use a type that allows duplicates, a List<t> for example.
|
|
|
|
|
|
Hi,
You can use the HashSet as:
Hashset(Key(Type1), Value (List(Type2)))
Dictionary<string, List<object>> dicElements;
|
|
|
|
|
In datagridview filterpoup tool, combobox for dropdown shows distinct values of the table not gridview. So the combobox some times shows the value not in filtered gridview. For example .
I already removed all the records from datagridview the catagory column 'C' . So no more record in datagridview but when I popup combobox filter , that catagory 'C' still is there . So anybody can advice me how I refresh the combox item after filtering the datagridview.
With thanks
Pol
public void RefreshValues() {
if (!(this.DataGridViewColumn is DataGridViewComboBoxColumn)) {
DataTable DistinctDataTable = this.BoundDataView.ToTable(true, new string[] { this.DataGridViewColumn.DataPropertyName });
DistinctDataTable.DefaultView.Sort = this.DataGridViewColumn.DataPropertyName;
comboBoxValue.DataSource = DistinctDataTable;
}
|
|
|
|
|
Hi everybody,
How can i execute multiple dos commands on a c# function?
Here are my 3 commands to be executed:
"cmd.exe"
"cd c:\"
"TF get $Project_Path"
Last commands is for Team Foundation Server(TFS) to get latest operation for a project.
I've tried to do this operation with the below code but it did not work. Where is the error and how can i do it, run the 2 commands at the same time??
strCmdText1 = @" cd C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE";
strCmdText2 = @"TF get $/Project_Path /recursive";
System.Diagnostics.Process.Start("CMD.exe", strCmdText1);
System.Diagnostics.Process.Start("CMD.exe", strCmdText2);
|
|
|
|
|
Create a batch file containing all the commands and execute that file. What you have done above is to try and execute two totally independent commands, so it probably fails.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
You should just be able to run "TF" (TF.exe?) with parameters "get $/Project_Path /recursive" in the working directory you want to run it in.
|
|
|
|
|
Hi i want to insert the new XML tag in the existing file.
How can we insert the tag after a particular node using C#4.0
thanks
Harish
|
|
|
|
|
You can use the XmlNode.InsertAfter[^] method to insert new nodes into an xml document.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
HI THIS IS MY C# PROGRAM I WANT TO GET A BOOLEAN RESULT TRUE OF FALSE I DIDNT FIND ANY ERROR....BUT THE PROB IS ONLY THE EXECPTION PART IS GETTING EXECUTED...ITS A LOGIN PAGE,....
public bool validateuser(User u)
{
bool result = true;
try
{
string validateq = "select count(*) from register where user.username = @username and user.password = @passwd ";
cmd = new SqlCommand(validateq, con);
cmd.Parameters.AddWithValue("@username", u.username);
cmd.Parameters.AddWithValue("@passwd", u.password);
con.Open();
reader = cmd.ExecuteReader();
reader.Read();
int r = Convert.ToInt32(reader[0]);
if (r > 0)
{
result = true;
}
else
{
result = false;
}
return result;
}
catch (Exception ex)
{
result = false;
return result;
}
}
|
|
|
|
|
User is a reserved word, it must be escaped:
...where [user].username = @username and [user].password = @passwd
Do not forget to close your reader, a good place for that is in a finally clause:
try
{
}
catch(Exception ex)
{
}
finally
{
if (reader!=null)
reader.Close()
}
|
|
|
|
|
i tried it but the prob is the if part is not getting executed insted its going to catch part!
|
|
|
|
|
And what's the error message?
|
|
|
|
|
no error message thats making it more bad
|
|
|
|
|
There must be. If you are going into an exception handler, there has to be an exception.
|
|
|
|
|
s but instead of exception message i have given to return false result ;
|
|
|
|
|
We get that. We still need to know what exception you are currently getting to help diagnose the problem.
|
|
|
|
|
Come on!
What's that catch(Exception ex) thing? There it is. Use the debugger, or show it in a MessageBox, or write it to a log file...
|
|
|
|
|
Can you give an example of your table structure, because the query string doesn't seem right. Is the table you are querying register or user . Personally I think you should be looking to do something like this :- (assumes table where users info is kept is called users, substitute register if that is the correct table)
try
{
string validateq = "SELECT COUNT(userid) FROM users WHERE username = @username AND password = @passwd ";
SqlCommand cmd = new SqlCommand(validateq, con);
cmd.Parameters.AddWithValue("@username", u.UserName);
cmd.Parameters.AddWithValue("@passwd", u.Password);
con.Open();
return Convert.ToInt32(cmd.ExecuteScalar()) > 0;
}
catch (SqlException ex)
{
throw new Exception(ex.Message,ex) ;
}
I hope this helps.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Reason for my vote of one:
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|