473,563 Members | 2,668 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WPF Datagrid - 1st Row show checkbox, 2nd Row Hide Checkbox,...

10 New Member
hello! Its me again. I hope somebody can help me!

I don't know if it is possible but i hope so...

i have a datagrid with 2 Columns:

1 Column is a checkbox (template)
Expand|Select|Wrap|Line Numbers
  1. <DataGridTemplateColumn Header="geprüft">
  2.     <DataGridTemplateColumn.CellTemplate>
  3.         <DataTemplate>
  4.             <CheckBox Name="chk" Content="{Binding Path=geprüft}" IsChecked="False" IsThreeState="False"/>
  5.         </DataTemplate>
  6.     </DataGridTemplateColumn.CellTemplate>
  7. </DataGridTemplateColumn>
  8.  
and the last Column is a textbox binding with status

Expand|Select|Wrap|Line Numbers
  1. <DataGridTextColumn IsReadOnly="True" Width="auto" Header="status" Binding="{Binding Status}">
now, i only want to show the checkbox if status = 4... so in row1 = show, row2 = hide etc...

is it possible?

and how can i make an event on the checkbox (to save in db if checkbox is checked)

if i make an event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub chk_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles chk.Click
  2. End Sub
  3.  
I get an error:
Error Handles clause requires a WithEvents variable defined in the containing type or one of its base types.


hope somebody can help me!

Nice Greets,
Mathias
Attached Images
File Type: jpg Grid.jpg (7.4 KB, 641 views)
Nov 20 '12 #1
9 17205
Frinavale
9,735 Recognized Expert Moderator Expert
Hi Mathias,

Have you ever used converters before?
Create a class that implements the IValueConverter Interface so that you can bind your IsChecked property to the Status property. The converter will convert the 3, or 4 into a true or false value so that the IsChecked property will work.

-Frinny
Nov 20 '12 #2
Mathias123
10 New Member
Hello Frinny,
Thank you for your response! i try to do that... and hope it works.

But i think you don't understand what i need. (because my english is not so good)


1) I only want to see the checkbox when status = 4
If status = 3 or status = 2 or status = 1 then Hide the checkbox in the Row. (only visible on status = 4)

2) If i checked the checkbox in the row with status 4 i want to make an event in the Database. The Status should get the value 5 (Status 5 = Finished)


so is in this case the IValueConverter Interface the best solution?

nice Greets,
Mathias
Attached Images
File Type: jpg grid.jpg (15.7 KB, 389 views)
Nov 20 '12 #3
Mathias123
10 New Member
ok now i have a solution for the checkbox to save something in database... i only add Click="CheckBox _Click"

Code to go in a sub :)
Expand|Select|Wrap|Line Numbers
  1.  
  2. <DataGridTemplateColumn Header="geprüft"> 
  3.     <DataGridTemplateColumn.CellTemplate> 
  4.         <DataTemplate> 
  5.             <CheckBox Name="chk" Content="{Binding Path=geprüft}" IsChecked="False" IsThreeState="False" Click="CheckBox_Click"/> 
  6.         </DataTemplate> 
  7.     </DataGridTemplateColumn.CellTemplate> 
  8. </DataGridTemplateColumn> 
  9.  


But i have no solution for the first problem (checkbox visible or hidden for each rows)


Good Night, Good Fight!


Nice Greets,
Mathias
Nov 20 '12 #4
Frinavale
9,735 Recognized Expert Moderator Expert
You can get around this without using converters than...just use triggers like before but apply it to the CheckBox:

Expand|Select|Wrap|Line Numbers
  1. <DataGridTemplateColumn>
  2.     <DataGridTemplateColumn.CellTemplate>
  3.         <DataTemplate>
  4.             <CheckBox Name="chk" Content="{Binding Path=geprüft}" IsThreeState="False" Visibility="Collapsed">
  5.                 <CheckBox.Style>
  6.                     <Style TargetType="CheckBox">
  7.                         <Style.Triggers>
  8.                             <DataTrigger Binding="{Binding Path=Status}" Value="4">
  9.                                 <Setter Property="Visibility" Value="Visible" />
  10.                             </DataTrigger>
  11.                         </Style.Triggers>
  12.                     </Style>
  13.                 </CheckBox.Style>
  14.             </CheckBox>
  15.         </DataTemplate>
  16.     </DataGridTemplateColumn.CellTemplate>
  17. </DataGridTemplateColumn>

It seems that you have solved your second part of the question.

-Frinny
Nov 20 '12 #5
Frinavale
9,735 Recognized Expert Moderator Expert
If you weren't using triggers, and you wanted to try a converter you would do the following.

You would create a class that implements the IValueConverter interface. The purpose of this class would be to return the visibility (collapsed or visible) depending on the Status value. The convert back method would set the status to 5...

I'm just not 100% sure if it would work because I can't really try it....

But your class would look something like this:
(VB.NET)
Expand|Select|Wrap|Line Numbers
  1. Public Class StatusVisibilityConverter
  2.     Implements IValueConverter
  3.  
  4.     Public Function Convert(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
  5.         Dim is4Status As Boolean = CType(value, Integer)
  6.  
  7.         If is4Status = 4 Then
  8.             Return Visibility.Visible
  9.         End If
  10.  
  11.         Return Visibility.Collapsed
  12.     End Function
  13.  
  14.     Public Function ConvertBack(value As Object, targetType As System.Type, parameter As Object, culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
  15.         Throw New NotImplementedException
  16.         'In here you would have to try converting back somehow...I'm just not sure how
  17.     End Function
  18. End Class
(C#)
Expand|Select|Wrap|Line Numbers
  1. public class StatusVisibilityConverter : IValueConverter
  2. {
  3.  
  4.     public object Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
  5.     {
  6.         bool is4Status = Convert.ToInt32(value);
  7.  
  8.         if (is4Status == 4) {
  9.             return Visibility.Visible;
  10.         }
  11.  
  12.         return Visibility.Collapsed;
  13.     }
  14.  
  15.     public object ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture)
  16.     {
  17.         throw new NotImplementedException();
  18.         //In here you would have to try converting back somehow...I'm just not sure how
  19.     }
  20. }
Add your project's namespace to your window/user control/page:
Expand|Select|Wrap|Line Numbers
  1. <Window x:Class="Window1"
  2.         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3.         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4.         xmlns:myProject="clr-namespace:MyProjectNamespace"
  5.         Title="Window1" Height="760" Width="800"
  6.         Background="White">
Add your visibility converter as a resource to the Window/User Control/Page...or even as a resource to your grid...so that you can use it:
Expand|Select|Wrap|Line Numbers
  1. <Window.Resources>
  2.     <myProject:StatusVisibilityConverter x:Key="StatusVisibilityConverter" />
  3. </Window.Resources>
  4.  
Then change the XAML code for your CheckBox so that it's Visibility property is bound to your Status property and uses your new converter:
Expand|Select|Wrap|Line Numbers
  1. <DataGridTemplateColumn>
  2.     <DataGridTemplateColumn.CellTemplate>
  3.         <DataTemplate>
  4.             <CheckBox Name="chk" Content="{Binding Path=geprüft}" IsChecked="{Binding Path=Status}" IsThreeState="False"
  5.                       Visibility="{Binding Path=Status, Converter={StaticResource StatusVisibilityConverter}}" />
  6.         </DataTemplate>
  7.     </DataGridTemplateColumn.CellTemplate>
  8. </DataGridTemplateColumn>
-Frinny
Nov 20 '12 #6
Mathias123
10 New Member
Hi!

I try the first post (because I'm new in WPF) but it doesn't work... the property
Expand|Select|Wrap|Line Numbers
  1. <Setter Property="Visibility" Value="Visible" />
doesn't work?!

i try another Property
Expand|Select|Wrap|Line Numbers
  1. <Setter Property="IsEnabled" Value="false"/>
and it works... All other Properties work, but i don't know why the Property "Visibility " doesn't work...
Nov 21 '12 #7
Frinavale
9,735 Recognized Expert Moderator Expert
It would help if you posted the whole style because it worked when I tried it before posting...

-Frinny
Nov 21 '12 #8
Mathias123
10 New Member
now i tried your second post and it work!

thank you for your help!!!!!
Nov 21 '12 #9
Frinavale
9,735 Recognized Expert Moderator Expert
I'm glad it works.

Just make sure you implement the "convert back" method so that it works properly.

-Frinny
Nov 21 '12 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

13
74012
by: genetic.error | last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up before... The VS.Net MSDN file seems to state that the following should work: Form1.Show Form1.Visible = True Form1.Hide Form1.Visible = False Load (Form1)
2
5309
by: soundar rajan | last post by:
Hi, I wanna display messagebox, and also at the bottom i wanna display "Dont show again" with checkbox using VB.NET. Immediate help needed!!!!
0
1398
by: Mac via DotNetMonster.com | last post by:
I have a MDI parent form and the only control on it is a panel anchored to the left hand side. I have menu items on the MDI parent that show & hide this panel. Ideally I would like it to show by not pushing out the child forms, but rather be overlapping them. Alternatively I tried creating a form the same size as the panel but run into...
1
1815
by: DBC User | last post by:
I am wondering is there any way when I do a show and hide of a form, we can do a smooth transition to the new screen like power point presentation in c#?? Thanks.
6
8295
by: jesper_lofgren | last post by:
Hi, I wonder if its possible to show and hide a image with javascipt. I want the image to disapear from bottom and up very smooth, maybe under 3-4sec. Is it possible ? any tips ? Thanks
2
3367
by: Alistair George | last post by:
Hi in Delphi its a piece of cake to show and hide a mainform eg mainform.show mainform.hide. However, after finding similar actions in C# seem to result in destroy of form object, which causes errors maybe I am wrong, but here is what I have tried with no joy: private void TrayFormShow_Click(object sender, EventArgs e) {...
3
3343
by: timplx | last post by:
Hello all, New to javascript and have never worked with programming languages like c++, so my logic in some of these statements might be incorrect or redundant Got a problem with my page... using java and external css to show/hide items on the same click. I found a script that uses the getElementById function to adjust the display style of a...
0
8961
Frinavale
by: Frinavale | last post by:
This code snippet is just a little bit of fun. It demonstrates how you use JavaScript and CSS to show or hide columns in a table depending on whether or not a checkbox corresponding with the column is checked. <html> <head> <script type="text/javascript"> function ShowHideField(header, gridID, checkboxElement) { var theGrid =...
6
4342
oranoos3000
by: oranoos3000 | last post by:
i read below text that say about initial state display in css and relate with show and hide dom element do the below text describe this meaning that if we dont write display for element and hide that , it's display convert to hide and if again show that do convert display that to block or initial value related to html? for example for span if...
1
2355
oranoos3000
by: oranoos3000 | last post by:
hi my question is about jquery string show or hide in css that is set inside jquery method animate , are special for some css property or can be set for any css that is set inside animate method ?for example show or hide is special opacity or can set for width and height and i thank you if you describe with detail. and my another question...
0
7664
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7948
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.