|
The FindNode[^] method may be what you are looking for, but I may have misunderstood your question.
I must get a clever new signature for 2011.
|
|
|
|
|
S0784 wrote: For example I have three nodes in my TreeView and I Selected the second one - how can i get this information?
In treeview a node has lots of property which Information would you want to get.
treeView1.SelectedNode.Index.ToString();
treeView1.SelectedNode.Name;
treeView1.SelectedNode.Nodes.Count;
treeView1.SelectedNode.Level.ToString()
I have mentioned about someone property of treeview.
in case of any query let us know.
|
|
|
|
|
The SelectedNode property helped me a lot.
Thanks for your help.
|
|
|
|
|
Hello Everyone
Im generating two columns of dataGridView from database on click event button. The first column is FoodName, second column is FoodType.
On my dataGridView I have set it a click event so the user can enter a number on particular cell of the third column like so...
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 2)
{
string cellContent = "0";
if (this.dataGridView1[e.ColumnIndex, e.RowIndex].Value != null)
{
cellContent = this.dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
}
using (InputBox ib = new InputBox("Enter new stock amount:", this.dataGridView1[0, e.RowIndex].Value.ToString(), cellContent))
{
if (ib.ShowDialog() == DialogResult.OK)
{
this.dataGridView1[e.ColumnIndex, e.RowIndex].Value = ib.Result;
cellContent = ib.Result;
this.dataGridView1.Controls.Find("btn" + cellValue, true); "THIS IS THE LINE WHERE I WANT TO GET THAT cellFoodTypeValue...
}
}
}
}
How can I get the FoodType value from that row?
Here is the code of my click event button...
(Hence: ColFoodQtyStock and ColFoodStatus are template columns generated at run-time)
private DataGridViewTextBoxColumn ColFoodQtyStock = new DataGridViewTextBoxColumn();
private DataGridViewTextBoxColumn ColFoodStatus = new DataGridViewTextBoxColumn();
private void cmdStarters_Click(object sender, EventArgs e)
{
OleDbConnectionStringBuilder connBuilder = new OleDbConnectionStringBuilder();
connBuilder.DataSource = @"C:\Users\AP_AE\Desktop\DTPOS_APP\DataBase\DtposMenu.accdb";
connBuilder.Provider = "Microsoft.ACE.OLEDB.12.0";
connBuilder.Add("Jet OLEDB:Engine Type", "5");
string foodTypeSql = @"SELECT FoodName, FoodType FROM Food WHERE FoodType = @foodType";
using (OleDbConnection conn = new OleDbConnection(connBuilder.ConnectionString))
{
dataGridView1.Columns.Clear();
dataGridView1.RowTemplate.Height = 60;
dataGridView1.Visible = true;
dataGridView2.Visible = false;
try
{
OleDbCommand foodsCommand = new OleDbCommand(foodTypeSql, conn);
OleDbParameter foodType = foodsCommand.Parameters.Add("@foodType", OleDbType.VarChar, 15);
OleDbDataAdapter foodsDa = new OleDbDataAdapter(foodsCommand);
DataSet ds = new DataSet();
conn.Open();
foodType.Value = "Starter";
foodsDa.Fill(ds, "Food_table");
ds.Tables["Food_table"].Columns.Add(new DataColumn("Quantity In Stock", System.Type.GetType("System.Int32")));
ds.Tables["Food_table"].Columns.Add(new DataColumn("Status", System.Type.GetType("System.String")));
for (int i = 0; i < ds.Tables["Food_table"].Rows.Count; i++)
{
ds.Tables["Food_table"].Rows[i]["Quantity In Stock"] = 0;
ds.Tables["Food_table"].Rows[i]["Status"] = "<Always On Stock>";
}
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Food_table";
DataGridViewCellStyle dataGridViewCellStyle1 = new DataGridViewCellStyle();
this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
dataGridViewCellStyle1.Font = new Font("Verdana", 20.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.dataGridView1.Columns[0].Width = 420;
this.dataGridView1.Columns[1].Width = 180;
this.dataGridView1.Columns[2].Width = 300;
this.dataGridView1.Columns[3].Width = 308;
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex);
}
}
}
Any help please would be very greatfull
Thanks in advance
Lapeci
|
|
|
|
|
Something like this?
Obviously you change the column numbers to those required.
|
|
|
|
|
|
Hi,
something is wrong in the C# forum right now, so this message will not show as is, until things get fixed, and you won't be able to react either, you could however start a new thread if necessary.
My reply is rather simple: inside the ContentClicked handler, you know the row and column index of the cell you clicked; and you can access the Rows, Columns, and Cells arrays using integer indices. So you probably want
value=dataGridView1.Rows[e.RowIndex].Cells[the_index_of_the_column_you_want];
You may need a .Value at the end. Hope this helps.
|
|
|
|
|
Please ignore the above reply, there has been a cockup in the c# forum.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC League Table Link
CCC Link[ ^]
|
|
|
|
|
OK, the forum is alive again, so here we go:
IMO it is rather simple: inside the ContentClicked handler, you know the row and column index of the cell you clicked; and you can access the Rows, Columns, and Cells arrays using integer indices. So you probably want
value=dataGridView1.Rows[e.RowIndex].Cells[the_index_of_the_column_you_want].Value;
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Whats the most efficient way of storing and referecing a list of ~2000 unsorted key value pairs in C#?
I understand that there is not really any definite answer here since it will depend on the data, however, I'm not familiar enough with the .NET framework to know which ones to even test. I'm an MFC C++ developer who is migrating to C#. In MFC C++ I would use a CMap or a muiltidimensional array to store the data and it would be efficient enough for my needs. I'm finding in C#, neither (a series of arrays or a Hashtable) is working out very well. Both seem to be far less efficient than my implementations in C++ but I'm assuming this is mostly because of my inability to code C# as well as I do in C++.
For reference, I need to store 5-6 values for ~2000 keys (3-30 character strings) and receive between 200-10,000 updates a second (averaging about 750) total.
Recomendations? Should I look at another data storage method or should I work on improving my existing attempts?
|
|
|
|
|
I think a Dictionary should be fine. For most of the operations, execution time it proportional to number of elements in it (O(1)).
|
|
|
|
|
if you want to remember only one value (the most recent one) for each key you encounter, then yes a Dictionary is what you want, and
myDictionary[myKey]=myValue;
is all it takes.
Dictionaries are hashed; they are built on top of arrays, which when running out of their capacity are copied to larger ones. Therefore it may make sense to use a constructor overload that takes an initial capacity parameter.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Interested in what kind of 'performance' you are seeing and if you are running these tests in debug or release and if you are timing this in the IDE or not.
I have seen some interesting differences in speed and performance between these configurations before but when doing a test in a full production build outside the IDE they have ended up as very close to a wash. Also you may want to look at allocating new additions to the collections in groups rather than single records at a time. I have also seen that help performance wise.
|
|
|
|
|
Like others said, Dictionary<>() is a good bet. However, I wouldn't recommend using 3 - 30 character strings as the key. Performance will be better if you use something lighter like an int or something. You really haven't given us enough information to make a more informed design.
|
|
|
|
|
WTF?
This is not what I typed, and I can vote on it.
I can't delete or edit it.
Whats is wrong with this?
Also the other Answers do not appear to relate to the Question.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC League Table Link
CCC Link[ ^]
|
|
|
|
|
Dave, whatever it is you are doing in the C# forum, it is disruptive: the top thread is cut short, the next one is decapitated. You may want to get into your topmost message there and fix something. Thanks.
If you could note what the content is, and how things get fixed, it probably would be material for a sucks&bugs thread.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Thursday, January 13, 2011 10:11 PM
|
|
|
|
|
I replied showing some code to give a total for the cells in his DGV.
There was nothing like what appears in my post up there.
Something is amiss!
It wasn't me, it was a big boy who did it and then he ran away!
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC League Table Link
CCC Link[ ^]
|
|
|
|
|
OK, I'll take it to S&B authorities then.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
You have 2000 fixed string keys?
Or you are discarding after 2000 and starting over with a new set?
And are you sizing the collections before you use it? And exactly what are you timing?
|
|
|
|
|
I've searched and found examples on how to write to an excel file, but I'm having trouble figuring out how to code to read all lines of a txt (say 10000 lines) and then write a new row every time a delineator is found which is on a line all by itself. The columns are predefined.
My code is as follows, but is not complete, any help would any appreciated. Thank you.
StreamReader parseFile = new StreamReader(@"C:\temp\output.txt");
string fileRead = parseFile.ReadToEnd();
string line;
string year = DateTime.Now.Year.ToString();
while ((line = parseFile.ReadLine()) != null)
{
int linenumber = 0;
if (line.EndsWith("(null)") != true)
{
linenumber = linenumber + 1;
Excel.Range range = oSheet.get_Range("A" + linenumber, );
range.Value2 = line;
}
}
parseFile.Close();
|
|
|
|
|
This[^] CP Archive Item may help.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC League Table Link
CCC Link[ ^]
|
|
|
|
|
Hello,
I have a winform project (c#) with a media player embedded inside.
When I start playing a song, I can see the equalizer inside the WMP window.
I want to duplicate this window so I will see the same window twice (right side and left side of my winform window).
Can I do that?
I thought about adding another WMP which will play the same songs but I'm afraid that it won't play at the same time.
Thanks
|
|
|
|
|
I am trying to customize the IME UI windows in a C# application which custom draws all of its controls. The main form can get the WM_IME_SETCONTEXT, and a couple of other messages, but I don't see how to trigger the IME to tell my application when to open any of the IME windows (composition, reading, or candidate). Are there any C# samples that I can look at which do the same? Or any C++ for that matter?
Or does anyone have any idea what I might need to do to trigger the IME to request these windows be opened? I set the IME to use PRC Chinese and I see the WM_IME_COMPOSITION message. In response to that message, ImmGetCompositionString() returns zero length. Then I see no additional messages.
I am responding to WM_IME_SETCONTEXT by clearing the lPARAM and then passing it to the DefWinProc, allowing the latter to set the results.
Any help would be appreciated.
Update: It seems that the problem is the IME/IMM is not aware that it should be processing the WM_KEYDOWN, and I am getting WM_CHAR messages instead of WM_IME... messages for composition and more.
modified on Thursday, January 13, 2011 9:58 PM
|
|
|
|
|
I am working on implimenting a 3rd party API written in C++. The API pulls an image from a scanner. I have tried a few different ways of of working with the image struct but every attempt causes memory crashes with P/Invoke. Any suggestions would be appreciated.
Here is the C++ code and sample that comes with the device.
typedef struct {
int width;
int height;
int info;
unsigned char* pbuf;
} MY_IMAGE;
MY_IMAGE img1,img2;
img1.width = 864;
img1.height = 3000;
img1.info = 8;
img1.pbuf = (UCHAR *)new UCHAR[2*nWidth*nHeight];
img2.width = 864;
img2.height = 3000;
img2.info = 8;
img2.pbuf = (UCHAR *)new UCHAR[2*nWidth*nHeight];
ret=WScanSelectBuf(&img1, &img2,0);
---------------------------------------------------------------------
[StructLayout(LayoutKind.Explicit)]
public struct MY_IMAGE
{
[FieldOffset(0)]
public int width;
[FieldOffset(4)]
public int height;
[FieldOffset(8)]
public int info;
[FieldOffset(12), MarshalAs(UnmanagedType.SysUInt)]
public IntPtr pbuf;
}
[DllImport("scandll.dll")]
private extern static int WT_ScanSelectBuf(ref MY_IMAGE image_down, ref MY_IMAGE image_up, int select);
public static int ScanSelectBuf(ref MY_IMAGE image_down, ref MY_IMAGE image_up, int select)
{
return WScanSelectBuf(ref image_down, ref image_up, select);
}
ImageInfo img1 = new ImageInfo();
ImageInfo img2 = new ImageInfo();
int nWidth = 864;
int nHeight = 1000;
img1.width = nWidth;
img1.height = nHeight;
img1.info = 8;
img2.width = nWidth;
img2.height = nHeight;
img2.info = 8;
ret = ScanSelectBuf(ref img1,ref img2, 0);
|
|
|
|
|
At a first glance, this is what I would do:
Declare MY_IMAGE as a class, not as a struct; use LayoutKind.Sequential instead of Explicit; remove FieldOffset attributes; do not use MarshalAs for pbuf field (pbuf should be an IntPtr); import the function without the ref keywords.
To assign the value to pbuf field you need to have the bytes in a byte[] array. Then you just have to set pbuf to the address of that array, using Marshal.UnsafeAddrOfPinnedArrayElement method.
|
|
|
|
|