|
In windows explorer you can select multiple files using combinations of ctrl and shift clicking, then if you click and hold the mouse button on one of the already selected files you can drag all the selected files to wherever. I'm trying to reproduce this kind of behavor in the windows forms datagrid, but the problem is that when I click and hold the mouse button on an already selected row (clicking on the row header) all the other selected rows get cleared (i.e. unselected) and only the clicked on row remains selected! I thought I could get around this by keeping track of all the selected rows, intecepting the MouseDown event on an already selected row and then restoring all the other rows that are supposed to be selected using DataGrid.Select. However, this doesn't seem to work. It appears that the rows get cleared *after* the MouseDown event and, therefore, after my code to restore the selected rows.
This is very frustrating!
Does anybody have any ideas on how I can make this work? I have to restore the selected rows while the user still has the mouse button down so that they can drag them or else stop the control from clearing the rows.
Thanks
[EDIT: here's a code snippet of what I've tried]
<br />
private void dgResults_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
<br />
bool shift = (Control.ModifierKeys & Keys.Shift) == Keys.Shift;<br />
bool ctrl = (Control.ModifierKeys & Keys.Control) == Keys.Control;<br />
<br />
DataGrid.HitTestInfo hti = dgResults.HitTest(e.X,e.Y);<br />
if (hti.Type == DataGrid.HitTestType.RowHeader)<br />
{<br />
if (dgResults.IsSelected(hti.Row))
{<br />
if (ctrl)<br />
{<br />
}<br />
else if (shift)<br />
{<br />
}<br />
else<br />
{<br />
foreach (int i in SelectedRows)<br />
{<br />
dgResults.Select(i);<br />
}<br />
}<br />
} <br />
else <br />
{<br />
}<br />
}<br />
}<br />
|
|
|
|
|
You will have to subclass the DataGrid
Implement the following methods
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
...
}
public override bool PreProcessMessage(ref Message msg)
{
Keys keyCode = (Keys)(int) msg.WParam & Keys.KeyCode;
switch (keyCode)
{
case Keys.Shift:
...
case Keys.ShiftKey:
...
case Keys.Alt:
...
case Keys.Control:
...
}
}
|
|
|
|
|
Thanks, by subclassing the DataGrid (which I was thinking I might do anyway so I could reuse the functionality) and overriding OnMouseDown method I can get the MouseDown behavor I want by simply not letting it call the base.OnMouseDown method when the MouseDown event occurs on an already selected row.
Now I have one more slight complication. If the use clicks down on an already selected row they might be getting ready to drag the selected rows, or they might just want to select that row only. The difference is whether they mouse up again. So on the MouseUp event I need to clear all the selected rows and reselect only the row the mouse is currently on. Trouble is that there is no DataGrid.Deselect function
Any ideas?
|
|
|
|
|
I had this problem and wound up actually keeping a separate list in memory that held whether a particular row was selected or not. It was a pain in the butt, but was the only way I could get the functionality to work. Too bad Microsoft didnt expose more of the DataGrid functions. All of the functions you need to override are there, but are either "internal" or "private", so there's not much you can do unless you hack your way into the framework.
|
|
|
|
|
Actually, I am also keeping an internal list of the selected rows as well just to save having to iterate through the whole table just to figure out which rows are selected. I agree it's a pain and a mystery why MS didn't add a DataGrid.SelectedRows property in the first place. One wonders if MS doesn't only provide the very basic functionality in the controls provided with the framework in order to create a market for developers to make and sell their own custom controls.
|
|
|
|
|
Okay, answered my own question. I can make it work by having OnMouseUp call OnMouseDown and setting a flag in the OnMouseUp method to tell OnMouseDown to let this "fake" mouse down event call the base method. It does seem like a awfully round-about way to do things though so does anybody have a better idea?
|
|
|
|
|
How embarrassing! I just found DataGrid.UnSelect!
Come on Microsoft, UnSelect? What was wrong with Deselect ?
|
|
|
|
|
Check your sorting with it. I dont have the code available to me, but I remember I ran into some problem that caused me to use my own list instead of relying on the DataGrid's because there was some deficiency.
|
|
|
|
|
I have a main dialog. I then create many new dialog forms which the user interacts with to enter values. I want to be able to retrieve the values that the user enters.
I am wondering the best way to design my system to allow access to the values entered by the user in the dialog forms. In my main form, I could add a public access to the dialog form instance. This seems inefficiant and seems to need a lot of effort to maintian.
Or perhaps I could update some central class with the entered values. Then I would access that class to retrieve the values.
I am sure this is a common thing that has to be done. Does anyone have suggestion as to the best way to achieve this?
Thanks,
Liam
|
|
|
|
|
There are loads of ways of doing this, here are 2
The simplest and worst of them is to change your controls to be public (I think this works, but would not recommend it)
Expose some public properties on your form to read the variables.
eg.
public string MyTextBoxValue
{
get
{
return TextBox1.Text;
}
}
you can also do clever things with a static factory method on the form which takes parameters as refs
HTH
Russ
|
|
|
|
|
I am trying to places buttons WITHIN a treeview control. SO, up in the top right hand corner you will see several buttons that perform several tasks. I have been able to anchor the buttons to the top right hand corner of the treeview control. However, when I introduce a splitter between TWO treeview controls, the buttons no longer anchor to the top right of the control. This is depedent upon the location of the splitter. For example, if the splitter is placed at the top of the control, then when the splitter is moved up and down, the buttons do not follow. However, they will continue to follow left and right when the form is resized. Any help would be much appreciated. Thanks.
D
|
|
|
|
|
I would use a toolbar placed exactly above the tree view, and not over it. Or put the buttons inside a panel, placed above the tree view.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
The problem with that is, I have two treeveiws ontop of one another. They are separated only by a splitter.
|
|
|
|
|
A splitter works by resizing a control docked to a side of the form. The control that fills the form automatically is resized to keep filling the form. So you can only have two controls, one on each side of the splitter. But those control can be Panels, which can contain other controls.
So, a short solution: put panels on you form and separate them with a splitter. Put the TreeView and the buttons on one Panel , and you're all set.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
Thanks for your help. Worked great!
|
|
|
|
|
You're welcome! I'm glad I could help
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
Greetings!!
I need to get some text from paragraphs on html pages and i did the next regular expression:
<\s*p[^>]*>(?<1>[\s\S]*)<\s*/\s*p\s*>
where <1> is the group in witch i store all text inside a paragraph.
It works fine on one paragraph.
If i have this sample:
<p> hello 1 </p>
<p> hello 2 </p>
<p> hello 3 </p>
i only get one paragraph that is:
hello 1 </p>
<p> hello 2 </p>
<p> hello 3
What is wrong????
please help me.
thanks.
Bruno Conde.
|
|
|
|
|
It's nothing wrong. The pattern you have made is supposed to work that way.
Make the pattern that mathes the text non-gready by adding a question mark:
[\s\S]*?
---
b { font-weight: normal; }
|
|
|
|
|
Thank you very much for your reply...
It was realy that.
pharaoh
|
|
|
|
|
Hello,
I'm trying to feed a structure to some unmanaged code, the function in the unmanaged code i supposed to fill-in some fields. Can someone help
me translate (marshal) the following to unmanaged code, I have very little experience with this stuff.
Greetz
Dave
Original C++ header code:
typedef struct
{
uint32 uiStructureSize ; // Must be sizeof (tsAT_RETURN_TEMPLATE) (input)
void* pTemplateBfr ; // Buffer to receive template (input/output)
uint32 uiTemplateBfrSize ; // Size of buffer @ pTemplateBfr (input)
uint32 uiTemplateSize ; // Size of template data returned (output)
uint16 uwTemplateQuality ; // Returned template quality (output)
} tsAT_RETURN_TEMPLATE ;
typedef struct
{
uint32 uiStructureSize ;
void* pImageItem ;
void* pOldTemplate ;
BOOL bReturnTemplateOK ;
tsAT_RETURN_TEMPLATE sReturnTemplate ;
} tsAT_BUILD_OR_UPDATE_TEMPLATE ;
My structure's in C#
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct tsAT_RETURN_TEMPLATE
{
public UInt32 uiStructureSize;
public Byte[] pTemplateBfr;
public UInt32 uiTemplateBfrSize;
public UInt32 uiTemplateSize;
public UInt16 uwTemplateQuality;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct tsAT_BUILD_OR_UPDATE_TEMPLATE
{
public UInt32 uiStructureSize;
public Byte[] pImageItem;
public Byte[] pOldTemplate;
public Boolean bReturnTemplateOK;
public tsAT_RETURN_TEMPLATE sReturnTemplate;
}
|
|
|
|
|
how to get the hyperlink column value,from data grid,i show the datagrid in show model dialog box,in run time when i click the column,i want the clicked column value and url field value
m mohamad rafi
|
|
|
|
|
how to get the hyperlink column value,from data grid,i show the datagrid in show model dialog box,in run time when i click the column,the clicked column valu and url field value
m mohamad rafi
|
|
|
|
|
HI All,
Am not an expert here, infact i need an expert to help me.
can any 1 here plz tell how to create an interface which can hold 3d objects in other words, a 3d object library using C#.net
you can directly email to me also.
Jennifer Wadhani
jenniferaahmed@yahoo.com
|
|
|
|
|
There is a directX interface for managed code.
There are loads of samples on the web, it takes abit of getting used to though.
Russ
|
|
|
|
|
How can I make my windows form get maximized onload?
Also, the controls, must I set the size to make it go maximum with respect to the main window?
I want the client window (a control type) to maximize the space left after the menu, toolbars.
|
|
|
|