|
Hi,
Can anyone tell me (via example is preferred) how to bind to a
CheckedListBox in a Windows Form? All the docs I've seen allow you to bind to a control property (i.e. TextBox.Text) to an instance variable property. How do you bind to both the 'ItemText' and 'Checked' values for each Item in a CheckedListBox?
TIA,
Matt
p.s. Also, I'm new here and I did look for a way to search all threads on the C# Discussion board but did not see how. Please advise.
|
|
|
|
|
The CheckedListBox does not support data-binding like that. First, you can add whatever objects you want to it. If the objects you're adding have ItemText and Checked properties, then you merely need to coordinate the event handlers for the CheckedListBox and set the Checked property of your object so that you can keep track of what's checked and what's not.
public class MyItem
{
private string itemText;
private bool checked;
public MyItem() : this(null, false)
{
}
public MyItem(string itemText, bool checked)
{
this.itemText = itemText;
this.checked = checked;
}
public string ItemText
{
get { return this.itemText; }
set { this.itemText = value; }
}
public bool Checked
{
get { return this.checked; }
set { this.checked = value; }
}
}
public void AddItem(MyItem item)
{
int index = checkedListBox1.Items.Add(item);
checkedListBox1.SetItemCheckState(index,
item.Checked ? CheckState.Checked : CheckState.Unchecked);
}
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
MyItem item = checkedListBox1.Items[e.Index];
item.Checked = e.NewValue == CheckState.Checked;
} You can always get the items out of CheckedListBox.Items whenever you want.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
This is my first project with a DataGrid.....
Is there any way to enable a full row select when the user clicks on a cell. By this I mean highlight the entire row when the user click on any cell. The reason I need this is that I do not want the user to have access to any contaxt menus other than the one I createdn and my context menu does not appear unless the full row is highlighted...
|
|
|
|
|
Not without creating custom DataGridColumnStyle classes (which could derive from either DataGridTextBoxColumn or DataGridBoolColumn so you don't have to redefine them), getting the row, and selecting that.
Really, though, this sounds like an issue with your code. If the context menu doesn't work without selecting the entire row, then your code isn't as robust as it should be.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi GS,
I had used the code below to achieve the above functionality in my last project. In DataGrid's Mouse Down event paste the below code:
private void DataGrid1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
<br />
<br />
System.Drawing.Point pt = new Point(e.X, e.Y); <br />
<br />
DataGrid.HitTestInfo hti = DataGrid1.HitTest(pt); <br />
<br />
if ( e.Button ==MouseButtons.Left)
{<br />
if(hti.Type == DataGrid.HitTestType.Cell) <br />
<br />
{ <br />
<br />
DataGrid1.CurrentCell = new DataGridCell(hti.Row, hti.Column); <br />
<br />
DataGrid1.Select(hti.Row); <br />
<br />
} <br />
}<br />
<br />
}
Do reply, whether It solved your purpose?
Regards,
Jay
|
|
|
|
|
Works great, one thing though....were you able to highlight the selection also ?
My context menu shows up now, but the item is still not highlighted unless I click on the left most column of the DataGrid control. But this is trivial, the funtionalitly is there thanks for the help.
|
|
|
|
|
Hi GS,
Sorry, I was in hurry, that is why could not refer my last project minutely. Please paste the above code in MouseUp Event. The row will get highlighted whenever any cell is clicked.
Do revert back whether you could achieve the functionality.
[Note:tomorrow and day after tomorrow(28th and 29th) I am on leave.]
Regards,
Jay.
|
|
|
|
|
Works perfectly Jay, thank you.
|
|
|
|
|
I have an array made up of a cutom structure called sl1. How can I find the index of the sl1 object, in the array, that has a name property equal to value I'm searching for? 
|
|
|
|
|
In this case it'd be better to implement a list or collection (for instance, derive from CollectionBase ) and override the indexer or even add your own so that in the get accessor you enumerate your structs stored in the internal ArrayList (the List property inherited from CollectionBase , or your own if you just implement the necessary interfaces like IList , which inherits from ICollection , which inherits from IEnumerable ) and find the struct with the name property equal to the value you pass, like so:
public MyStruct this[string name]
{
get
{
if (name == null) throw new ArgumentNullException("name");
foreach (MyStruct s in List)
if (string.Compare(s, name) == 0) return s;
throw new ArgumentException("The structure was not found.", "name");
}
} Using just an array of your structs, you won't be able to do what you want unless you implement your own IComparer and call one of the Array.BinarySearch overloads which takes an IComparer implementation as a parameter.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there a generic way of saying "everything" in a parameter of an oleDbDataAdapter? For instance, if my query asks for all rows WHERE (Name = ?), and then later in my code somewhere I have
Adapter.SelectCommand.Parameters[Name].Value = "some name";
What could I put in place of "some name" that would just mean everything...or is it even possible? Also, what if Value wasn't expecting a string, what if it was a bool...what can I put to basically ignore this parameter? Thanks a bunch for any help. I tried looking it up, but I didn't know what to search for. 
|
|
|
|
|
If you leave it blank, it should use all the values in your select statement
|
|
|
|
|
You'll get an exception since the parameter contained no value, thus leaving a SQL statement like this to be executed:
select * from SomeTable where Name = That doesn't parse correctly and therefore won't execute.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
When you use paramterized queries, you declare what type the parameter is. Value is an object so you can assign anything.
Because your query uses = and not LIKE , there's nothing you can really do other than have multiple SQL commands or command strings and use whichever is appropriate if you don't want to supply a value.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
PWLX_NOTIFICATION_INFO for winlogin notification package is defined in Winwlx.h file. how i will use it in C#, where i can't include header files ???
@!$h@
|
|
|
|
|
Wrong language - C and C++ allow you to include header files.
Find the header file, find the text you are looking for ("PWLX_NOTIFICATION_INFO") and find out what it equates to.
In C# write something like:
const uint PWLX_NOTIFICATION_INFO = 0x80001234;
or what ever the value might be. Then repeat for as many values in the set as there are.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
Coming soon: The Second EuroCPian Event
|
|
|
|
|
|
hi i want to know the matrix determinant yes there is a
cofactor method of determinant in3d matrix i think so is there any code for this
and
if there is 2d what is the code for 2d matrix determinant
matrix determinant
|
|
|
|
|
|
|
Hello everybody.
I'm creating a C# application that uses the Visio Drawing Control and Visio SDK.
Basically, I have a windows form with the Visio control on it and the user and drag and drop objects from the Visio stencil. I am managing the OnShapeAdd and the OnShapeDelete just fine.
My problem is I don't know how to detect the event when the user just moves a shape. I need to do this due to the logic of this application. I don't see anything like 'move' or 'drag' in VisEventCodes.
Any help will be greatly appreciated.
Thanks in advance.
|
|
|
|
|
The documentation isn't specific on whether or not the ShapeChanged event is fired when a shape is moved, but since this would change the location properties of the shape then it's possible. Try handling the ShapeChanged event and see if that works.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you very much, but the ShapeChanged event never seems to get triggered!
Much as I move of reshape or edit the text in a shape, I never get it triggered! ????
|
|
|
|
|
I'm doing this inside my AddAdvise method:
newEvent = documentEvents.AddAdvise(<br />
(short)VisEventCodes.visEvtMod +<br />
(short)VisEventCodes.visEvtShape,<br />
(IVisEventProc)this, sink, targetArgs);
And it doesnt seem to work.
However, this works perfectly:
newEvent = documentEvents.AddAdvise(<br />
(unchecked((short)VisEventCodes.visEvtAdd) +<br />
(short)VisEventCodes.visEvtShape),<br />
(IVisEventProc)this, sink, targetArgs);
???
|
|
|
|
|
Use the PIA for Visio (Microsoft.Office.Interop.Visio.dll, which you can download from MSDN[^] for Office XP and which comes with Office 2003 Professional) and just handle the event like so:
ApplicationClass app = new ApplicationClass();
app.ShapeChanged += new EApplication_ShapeChangedEventHandler(OnShapeChanged);
private void OnShapeChanged(object sender, IntPtr args)
{
} I'm not sure if this will work, however. You mentioned in a previous reply that it doesn't seem to be firing. It was only an educated guess, since no other event really seems to be appropriate.
Microsoft MVP, Visual C#
My Articles
|
|
|
|