|
Hi all
Just a quick question
I have created a datagrid view populated it with data and added a combobox using DataGridViewComboBoxColumn. This all works fine but a user has asked if it would be possible to over right the options for example:
The dropdown would contain strings "One" "two" "three" but the user would like the option of typing "seven" into the cell
Any ideas would be most appreciated as I have hit a wall!!!
Thanks
John
|
|
|
|
|
I have a listbox(default except theat the selectionmode is "multisimple") that I'm populating dynamically through a BindingSource, with the display and value member set to the same column. On loading of the form, I need to set the initial selected value(s) to a previously-stored value. I declare a List<string> called toSelect and fill it with the correct values. My problem is actually taking those values and selecting the correct listbox item(s).
What I currently have is:
foreach (string s in toSelect)
{
if (uxlbSuite.Items.Contains(s))
{
uxlbSuite.SelectedItems.Add(s);
}
}
The problem is that uxlbSuite.Items.Contains(s) always returns false, and the uxlbSuite.SelectedItems.Add(s) doesn't actually do anything if I don't perform the if check. I think I'm accessing the SelectedItems list wrong, but I'm baffled as to the correct way, and advice would be greatly appreciated.
|
|
|
|
|
Hi Drew,
to locate an item by its string value you want FindString() or FindStringExact()
The SelectedItems collection represents an observed state of the listbox, changing it
does not change the listbox state. You want SetSelected().
Luc Pattyn
|
|
|
|
|
Thanks for the response. What I ended up getting working was looping through the items list (which will never be more than a dozen or so), rather than the List<> of items that needed to select. From that, I could parse the correct object from the associated datarow (by casting it as such) and then compare that to the list of approved items.
uxlbSuite.SelectedItems.Clear();
List<object> objectsToAdd = new List<object>();
foreach (object unit in uxlbSuite.Items)
{
System.Data.DataRowView Row = unit as System.Data.DataRowView;
if (Row != null && toSelect.Contains(Row["ID"].ToString()))
{
objectsToAdd.Add(unit);
}
}
foreach (object unit in objectsToAdd)
{
uxlbSuite.SelectedItems.Add(unit);
}
|
|
|
|
|
Hi,
I have a combobox with a dropdownstyle of DropDown. I have my DataSource and DisplayMember set up in the combobox properties like so:
DataSource = bindingSourceFollowUpCodes
DisplayMember = Legend
ValueMember = FollowUpCode
I have tried to set the properties to update correctly but I can't figure out how to do it. I have searched all over for an answer. I can do this properly in code. Could someone see if they can figure out what the correct property setting s would be to do this without code?
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
// Get Groups list
CommandGetFollowUpCodes getFollowUpCodes = new CommandGetFollowUpCodes("%");
m_FollowUpCodes = (FollowUpCodeList)m_AppController.ExecuteCommand(getFollowUpCodes);
// Bind controls
bindingSourceFollowUpCodes.DataSource = m_FollowUpCodes;
comboBoxFollowUpCode.SelectedItem = null;
GroupItem itmGroup = (GroupItem)bindingSourceDefault.Current;
foreach (FollowUpCodeItem itmFollowUpCode in m_FollowUpCodes)
{
if (itmGroup.FollowUpCode == itmFollowUpCode.FollowUpCode)
{
comboBoxFollowUpCode.SelectedItem = itmFollowUpCode;
}
}
}
private void comboBoxFollowUpCode_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBoxFollowUpCode.SelectedItem != null)
{
GroupItem itmGroup = (GroupItem)bindingSourceDefault.Current;
FollowUpCodeItem itmFollowUpCode = (FollowUpCodeItem)comboBoxFollowUpCode.SelectedItem;
itmGroup.FollowUpCode = itmFollowUpCode.FollowUpCode;
}
}
Thanks,
Darren
|
|
|
|
|
Darren D wrote: DisplayMember = Legend
ValueMember = FollowUpCode
These are variables that contain the names you want ?
Darren D wrote: what the correct property setting s would be to do this without code?
Why are people so obsessed with codeless 'programming' nowadays ? I don't think you can link combo boxes in the designer so it works this out for itself.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Legend and FollowUpCode are the field names. The list is working fine. I don't seem to be able to bind the property that stores the target of the lookup table. If I bind it then the first item from the list shows up every time I load the form. I can select a value from the list but it never saves. The code I wrote works fine. There should be a way to do this without code I am just not getting it. 'Codeless' programs have less bugs I think.
DD
|
|
|
|
|
Darren D wrote: There should be a way to do this without code I am just not getting it.
No, there isn't. How is this "codeless" engine suppose to know wht you want if you put two ComboBox's on a form? Are they supposed to be independant or each other or is one list suppsoed to change with the item picked in the other? There's no way to tell.
Darren D wrote: 'Codeless' programs have less bugs I think.
They sure do! But this is because there is also no application when you have no code stitching the controls together, not to mention how the business rules work, or the data storage, ...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Well...I could do this in VB6. Why can't I do it in C#?
I am just setting properties on the combobox for everything but saving whatever the user picked from the list. It's not really "codeless."
This is just my "View." There will be business rule code in the Model.
DD
|
|
|
|
|
Hello,
I have an application which sits all the time in system tray. And i want to set user off, when he is inactive.
How can I get Windows MouseMove and Windows Keypress events?
Thanks.
|
|
|
|
|
I believe the only event that any icon, tray or system menu, gets, is the click event.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Have a look at the many "screen saver" articles on Code Project to learn
how to detect user activity. I havent done this myself, but I expect it
to be rather simple.
Luc Pattyn
|
|
|
|
|
Monin D. wrote: i want to set user off, when he is inactive.
Wait for the user to become inactive. Light fuse - get away. Should explode in 5 seconds.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi,
I have one instance of Printdocument for Grid and one for Chart. I want to show these two print documents in a single Print Preview dialog box. Any ideas how to do using C#?
Thanks
kumar
|
|
|
|
|
I have not done this, but I guess it is not hard to do.
I assume there is a single page of grid and a single page of chart, and you want
to combine them on a single page.
I further assume the grid and chart each are paintable on screen; rather than doing
it in the PaintHandler directly, I would provide an indirection, something like:
private void XXX_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {
XXX_Painter(e.Graphics, 0, 0, Width, Height);
}
private void XXX_Painter(Graphics g, int x, int y, int width, int height) {
// normal paint actions
}
so the actual painting is handled in a method that accepts 4 ints (or one rect) to
indicate the painting bounds. For screen painting inside a panel, the origin would be 0,0
and the size would be Width,Height of the panel itself.
Now the printdoc:
- in the printDoc constructor, attach a PrintPage handler (as always):
PrintPage+=new PrintPageEventHandler(PrintDoc_PrintPage);
- in the PrintPageEventHandler, call both XXX_Painter methods, each with an
appropriate set of x,y,width,height values
- optionally do some more g.DrawString() to annotate the graphics.
Hope this is helpfull.
Luc Pattyn
|
|
|
|
|
Thanks for the early reply. But my problem is, for Grid i am using thirdparty GridPrintDocument instance, which formats the grid as-is(including the image and other stuff) and gives output to Print or PrintPreview dialog.
And on the other hand for Chart I am using PrintDocument of System.Drawing.Printing . These work fine if i invoke Print Preview dialog separately for Grid and Chart.
I already did as you suggested but the problem is, it is removing the format of the Grid(image of the Grid), which i used to get using thirdparty GridPrintDocument instance, when single instance Print Preview is invoked for both Grid and Chart. And just shows the data in the grid as plain text.
Say for example i want to display two pages in a Print Preview dialog, one for Grid - same like the image i used to get using thirdparty GridPrintDocument instance and second page is Chart from normal System.Drawing.Printing's PrintDocument class.
Is there any way? Hope you got my point.
Thanks
Santosh
|
|
|
|
|
I see two more possibilities
I now assume the two existing halfs (grid and chart) each provide their own OnPrintPage handler.
1. with fake PrintPageEventArgs
As said before, provide a PrinPageHandler; in it:
- create a new PrintPageEventArgs based on the PrintPageEventArgs you get as an input,
but with modified PageBounds
- call grid.OnPrintPage
- do similar for chart
2. with bitmaps
As said before, provide a PrinPageHandler; in it:
- create a bitmap with the size of your print page (from PrintPageEventArgs)
- create a graphics from that bitmap (Graphics.FromImage)
- pass that graphics plus original PrintPageEventArgs to grid.OnPrintPage, so now
the grid is in your bitmap (rather than on paper)
- do similar for chart
- now on the original graphics (from PrintPageEventArgs) draw the first grid's bitmap
with g.DrawImage and appropriate bounds; this puts it on paper
- similar for chart
drawback for method 2. is scale reduction may not be optimal, since graf/chart now
have first been bitmapped, then scaled
You would have to experiment with these to see what it gives...
Luc Pattyn
|
|
|
|
|
sorry Luc, somehow i could not able to come-up to desired results. If possible can me give me a sample project?
Thanks
Santosh
|
|
|
|
|
As I said before, I never did such a thing; I only have very simple print code.
Luc Pattyn
|
|
|
|
|
hmmm... i guess it may not work as desired. I have totally two different types of PrintDocuments with different format capabilities, which need to get merged into single PrintPreviewDialog.
Thanks for your time and explanation
|
|
|
|
|
Hi,
looking around some more on CodeProject I found this article[^] that fits rather well in my last suggestion. I did not study the details but
I suggest you give it a try.
Regards,
Luc Pattyn
|
|
|
|
|
Which version of .NET Framework are you using ?
Luc Pattyn
|
|
|
|
|
sorry for late reply i am using .Net 2.0
Thanks
kumar
|
|
|
|
|
hi
i want to use iframe tag and set src to one htm file that have picture, but when i use this tag,pictures is not appeare in my webpage,but when i use htm file in browser, it show pictures. where is the problem and how to show full my htm file(with images) in ?
my code is : <code><iframe id="ifr1" src="myHtmfile.htm"></iframe></code>
<b>Note : the images folder already exist in my project.</b>
Thanks
|
|
|
|
|
Why are you reposting this? I asked you to post your code on the other instance of this question.
|
|
|
|